resize ing image whn uploading php

Discussion in 'Yahoo' started by m.rifath, Jan 16, 2008.

  1. #1
    I have a requirment to reseize a image whn uploding, it is working fine, but if i upload big image. it is resizing the images, pleae can u all help.


    here is my code

    <?
    include '../../db/cnn.php';

    $sSqlSel="SELECT max(id) sid FROM testimage";
    $sSqsel=mysql_query($sSqlSel);
    $nRec=mysql_num_rows($sSqsel);
    $sDatawis=mysql_fetch_object($sSqsel);
    $sIds=$sDatawis->sid;
    $sIncId=$sIds+(int)2;

    $sDispThFull="/webgate/cms/admin/images/full/";
    $sDispThThum="/webgate/cms/admin/images/thum/";

    if($_POST['Submit']) {

    if($_FILES['photo1']['tmp_name']){
    $sRoot=$_SERVER['DOCUMENT_ROOT'];
    $uploadDir = $sRoot .'/webgate/cms/admin/images/full/';
    $uploadDir1= $sRoot .'/webgate/cms/admin/images/thum/';

    $sFile =$_FILES['photo1']['name'];
    $sPath=$_FILES['photo1']['tmp_name'];

    $sExt=strrev(substr(strrev($sFile),0,strpos(strrev($sFile),".")));
    //$sExt=substr($sFile,(strlen($sFile)-3),3);
    $sFilePath ="img" . $sIncId . "." . $sExt; //
    $sPhoto1=$sFilePath;

    $uploadFile = $uploadDir . $sFilePath;

    move_uploaded_file($sPath,$uploadFile); //

    $n_width=100; // Fix the width of the thumb nail images
    $n_height=100; // Fix the height of the thumb nail imaage
    $uploadFile1 = $uploadDir1 . $sFilePath;

    if($sExt=="jpg"){
    $im=ImageCreateFromJPEG($uploadFile);
    $width=ImageSx($im); // Original picture width is stored
    $height=ImageSy($im); // Original picture height is stored
    $newimage=imagecreatetruecolor($n_width,$n_height);
    imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
    ImageJpeg($newimage,$uploadFile1);
    chmod("$uploadFile1",0777);
    }

    if($sExt=="gif"){
    $im=ImageCreateFromGIF($uploadFile);
    $width=ImageSx($im); // Original picture width is stored
    $height=ImageSy($im); // Original picture height is stored
    $newimage=imagecreatetruecolor($n_width,$n_height);
    imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
    ImageGIF($newimage,$uploadFile1);
    chmod("$uploadFile1",0777);
    }

    if($sExt=="png"){
    $im=ImageCreateFromPNG($uploadFile);
    $width=ImageSx($im); // Original picture width is stored
    $height=ImageSy($im); // Original picture height is stored
    $newimage=imagecreatetruecolor($n_width,$n_height);
    imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height);
    ImagePNG($newimage,$uploadFile1);
    chmod("$uploadFile1",0777);
    }
    }
    $sSql="INSERT INTO testimage(imgsrc) VALUES('$sPhoto1')";
    $select=mysql_query($sSql);

    if($select){
    print "ok";
    } else {
    print "no" . mysql_error();
    }
    }
    ?>
     
    m.rifath, Jan 16, 2008 IP