Imagick::cropThumbnailImage

(PECL imagick 2.0.0)

Imagick::cropThumbnailImageCreates a crop thumbnail

Описание

bool Imagick::cropThumbnailImage ( int $width , int $height )
Внимание

К настоящему времени эта функция еще не была документирована; для ознакомления доступен только список аргументов.

Creates a fixed size thumbnail by first scaling the image up or down and cropping a specified area from the center.

Список параметров

width

The width of the thumbnail

height

The Height of the thumbnail

Возвращаемые значения

В случае успешной работы возвращает TRUE.

Ошибки

Бросает ImagickException при ошибке.

Коментарии

$image = new Imagick($path."test1.jpg");

$image->cropThumbnailImage(160,120); // Crop image and thumb

$image->writeImage($path."test1.jpg");
2008-03-03 19:06:23
http://php5.kiev.ua/manual/ru/function.imagick-cropthumbnailimage.html
I found a relevant posting complete with demo code at this site:
http://valokuva.org/?p=8

Sample code goes like this:
<?php
/* Read the image */
$im = new imagick"test.png" );
/* create the thumbnail */
$im->cropThumbnailImage8080 );
/* Write to a file */
$im->writeImage"th_80x80_test.png" );
?>

This is a specialization of the cropImage method. At a high level, this method will create a thumbnail of a given image, with the thumbnail sized at ($width, $height). 

If the thumbnail does not match the aspect ratio of the source image, this is the method to use. The thumbnail will capture the entire image on the shorter edge of the source image (ie, vertical size on a landscape image). Then the thumbnail will be scaled down to meet your target height, while preserving the aspect ratio. Extra horizontal space that does not fit within the target $width will be cropped off evenly left and right.

As a result, the thumbnail is usually a good representation of the source image.
2009-06-12 00:14:13
http://php5.kiev.ua/manual/ru/function.imagick-cropthumbnailimage.html
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);
?>
2010-06-03 15:57:28
http://php5.kiev.ua/manual/ru/function.imagick-cropthumbnailimage.html
It's worth noting that using cropThumbnailImage can appear to give undesired results if you're using .gif image formats. If you are using .gif's, you'll need to compliment this function with a removal of the canvas.

<?php

//instantiate the image magick class
$image = new Imagick($image_path);

//crop and resize the image
$image->cropThumbnailImage(100,100);

//remove the canvas
$image->setImagePage(0000);

?>
2011-11-30 08:01:32
http://php5.kiev.ua/manual/ru/function.imagick-cropthumbnailimage.html

    Поддержать сайт на родительском проекте КГБ