note 69191 deleted from function.imagecopyresampled by bjori

From: Date: Sat, 26 Aug 2006 11:17:03 +0000
Subject: note 69191 deleted from function.imagecopyresampled by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-116338@lists.php.net to get a copy of this message
Note Submitter: dannyt_ro at yahoo dot com ---- I modified a script in order to make a function that will resize an image to the desired dimensions keeping the proportions This function will delete the original "jpg" replacing it with the modified one. Good Luck! <? function resizeImage ($sourcefile, $dest_x, $dest_y, jpegqual) { /* Get the dimensions of the source picture */ $picsize=getimagesize("$sourcefile"); $source_x = $picsize[0]; $source_y = $picsize[1]; $source_id = imageCreateFromJPEG("$sourcefile"); //Keep the proportions on the resizd image if ($picsize[0]>$picsize[1]){ $ratio=$picsize[0]/$dest_x; $dest_y=$picsize[1]/$ratio; } else{ $ratio=$picsize[1]/$dest_y; $dest_x=$picsize[0]/$ratio; } /* Create a new image object (not neccessarily true colour) */ $target_id=imagecreatetruecolor($dest_x, $dest_y); /* resize the original picture and copy it into the just created image object. Because of the lack of space I had to wrap the parameters to several lines. I recommend putting them in one line in order keep your code clean and readable */ $target_pic=imagecopyresampled($target_id,$source_id, 0,0,0,0, $dest_x,$dest_y, $source_x,$source_y); /* Create a jpeg with the quality of "$jpegqual" out of the image object "$target_pic". This will be saved as $targetfile */ //Delete of the original file so that the new file cand be uploaded unlink($sourcefile); //Writing the desired image instead of the original image imagejpeg ($target_id,"$sourcefile",$jpegqual); return true; } ?>

« previous php.notes (#116338) next »