note 82343 added to function.getimagesize

From: Date: Mon, 07 Apr 2008 07:14:10 +0000
Subject: note 82343 added to function.getimagesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-137993@lists.php.net to get a copy of this message
*********************************** Copies Source Image to Destination Image *********************************** 1. Copies source image 2. Calculates image dimensions 3. Resizes image (you specify max height/width) 4. Retains aspect ratio 5. Writes destination image *********************************** This was created from a variety of code snippets I've found here at php.net and other places on the web. I take no credit for any of this code other than putting the pieces together. <?php $source_pic = 'images/source.jpg'; $destination_pic = 'images/destination.jpg'; $max_width = 500; $max_height = 500; $src = imagecreatefromjpeg($source_pic); list($width,$height)=getimagesize($source_pic); $x_ratio = $max_width / $width; $y_ratio = $max_height / $height; if( ($width <= $max_width) && ($height <= $max_height) ){ $tn_width = $width; $tn_height = $height; }elseif (($x_ratio * $height) < $max_height){ $tn_height = ceil($x_ratio * $height); $tn_width = $max_width; }else{ $tn_width = ceil($y_ratio * $width); $tn_height = $max_height; } $tmp=imagecreatetruecolor($tn_width,$tn_height); imagecopyresampled($tmp,$src,0,0,0,0,$tn_width, $tn_height,$width,$height); imagejpeg($tmp,$destination_pic,100); imagedestroy($src); imagedestroy($tmp); ?> ---- Server IP: 64.71.164.2 Probable Submitter: 66.177.221.36 ---- Manual Page -- http://www.php.net/manual/en/function.getimagesize.php Edit -- https://master.php.net/note/edit/82343 Del: integrated -- https://master.php.net/note/delete/82343/integrated Del: useless -- https://master.php.net/note/delete/82343/useless Del: bad code -- https://master.php.net/note/delete/82343/bad+code Del: spam -- https://master.php.net/note/delete/82343/spam Del: non-english -- https://master.php.net/note/delete/82343/non-english Del: in docs -- https://master.php.net/note/delete/82343/in+docs Del: other reasons-- https://master.php.net/note/delete/82343 Reject -- https://master.php.net/note/reject/82343 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#137993) next »