note 55740 deleted from function.imagecopyresampled by cmb

From: Date: Sun, 19 May 2019 16:03:47 +0000
Subject: note 55740 deleted from function.imagecopyresampled by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-211069@lists.php.net to get a copy of this message
Note Submitter: ---- Here is my own custom utility which I call "Thumbnailer" (I know it is cheesy). It's rather short, and it will take JPEG (you can change that easily), and format it to a specified output width and height as a PNG (or whatever else you choose): <?php //Dimensions $outWidth=100; $outHeight=75; //Do it $imgSrc=imagecreatefromjpeg("[source]"); $srcWidth=imagesx($imgSrc); $srcHeight=imagesy($imgSrc); //Make thumbnails $imgOut=imagecreatetruecolor($outWidth,$outHeight); imagerectangle($imgOut,0,0,$outWidth,$outHeight, imagecolorallocate($imgOut,0,0,0)); //Copy them proportionatly $dx=0; $dy=0; $dw=$outWidth; $dh=$outHeight; if ($outWidth*$srcHeight!=$outHeight*$srcWidth) { //Non-proportional, cut-off //Which dimensions is larger if ($srcWidth>$srcHeight) { //Empty space on top and bottom $dw=$outWidth; $dh=($dw*$srcHeight)/$srcWidth; $dy=($outHeight-$dh)/2; } else { //Empty space on left and right $dh=$outHeight; $dw=($dh*$srcWidth)/$srcHeight; $dx=($outWidth-$dw)/2; } } imagecopyresampled($imgOut,$imgSrc,$dx,$dy,0,0, $dw,$dh,$srcWidth,$srcHeight); //imagecopyresized for lower quality //Create the thumbnail and destroy everything else imagepng($imgOut,"[out]"); echo "Image created successfully: $outWidth x $outHeight, ".round(filesize("[source]")/1024)." KB<br>"; imagedestroy($imgSrc); imagedestroy($imgOut); ?> I just use this as a loop to create thumbnails for a series of ordered images.

« previous php.notes (#211069) next »