note 67832 deleted from function.imagecopyresampled by bjori

From: Date: Wed, 05 Jul 2006 21:13:12 +0000
Subject: note 67832 deleted from function.imagecopyresampled by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-114429@lists.php.net to get a copy of this message
Note Submitter: gviktor at gmail dot com Reason: in docs ---- For everybody who needs thumbs that are exactly 100x100 or so. The image is cropped to the right proportions, and scaled - simultaneously. (This code doesn't work if you have the bug described below in your installation.) <? /* resize and crop a gd image object to a given height and width */ function resize_and_crop($image, $width=200, $height=200) { $width_orig = imagesx($image); $height_orig = imagesy($image); // Get crop area and offset $scale_factor = max($width / $width_orig, $height / $height_orig); $width_crop = $width / $scale_factor; $height_crop = $height / $scale_factor; $x_offset = 0.5 * ($width_orig - $width_crop); $y_offset = 0.5 * ($height_orig - $height_crop); // Resample $image_p = imagecreatetruecolor($width, $height); imagecopyresampled( // ==target== ==original== $image_p, $image, 0, 0, $x_offset, $y_offset, $width, $height, $width_crop, $height_crop); return $image_p; } ?>

« previous php.notes (#114429) next »