note 98236 added to function.imagick-cropthumbnailimage
| From: | martijn at elicit dot nl | Date: | Thu, 03 Jun 2010 12:57:28 +0000 |
| Subject: | note 98236 added to function.imagick-cropthumbnailimage | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-169845@lists.php.net to get a copy of this message | ||
In my opinion this function is not working as expected, tested for imagemagick version 6.3.7
As described above, the function returns an image with a fixed height and a variable width.
Here's a fix that will return a cropped thumbnail with the defined dimensions, without
variations in the dimensions.
<?php
// define widescreen dimensions
$width = 160;
$height = 90;
// load an image
$i = new Imagick("your image file");
// get the current image dimensions
$geo = $i->getImageGeometry();
// crop the image
if(($geo['width']/$width) < ($geo['height']/$height))
{
$i->cropImage($geo['width'], floor($height*$geo['width']/$width), 0,
(($geo['height']-($height*$geo['width']/$width))/2));
}
else
{
$i->cropImage(ceil($width*$geo['height']/$height), $geo['height'],
(($geo['width']-($width*$geo['height']/$height))/2), 0);
}
// thumbnail the image
$i->ThumbnailImage($width,$height,true);
// save or show or whatever the image
$i->setImageFormat("png");
header("Content-Type: image/png");
exit($i);
?>
----
Server IP: 213.249.64.162
Probable Submitter: 84.245.17.50
----
Manual Page -- http://www.php.net/manual/en/function.imagick-cropthumbnailimage.php
Edit -- https://master.php.net/note/edit/98236
Del: integrated -- https://master.php.net/note/delete/98236/integrated
Del: useless -- https://master.php.net/note/delete/98236/useless
Del: bad code -- https://master.php.net/note/delete/98236/bad+code
Del: spam -- https://master.php.net/note/delete/98236/spam
Del: non-english -- https://master.php.net/note/delete/98236/non-english
Del: in docs -- https://master.php.net/note/delete/98236/in+docs
Del: other reasons-- https://master.php.net/note/delete/98236
Reject -- https://master.php.net/note/reject/98236
Search -- https://master.php.net/manage/user-notes.php