Imagick::scaleImage

(PECL imagick 2.0.0)

Imagick::scaleImageScales the size of an image

Description

bool Imagick::scaleImage ( int $cols , int $rows [, bool $bestfit = false ] )

Scales the size of an image to the given dimensions. The other parameter will be calculated if 0 is passed as either param.

Note: The behavior of the parameter bestfit changed in Imagick 3.0.0. Before this version given dimensions 400x400 an image of dimensions 200x150 would be left untouched. In Imagick 3.0.0 and later the image would be scaled up to size 400x300 as this is the "best fit" for the given dimensions. If bestfit parameter is used both width and height must be given.

Parameters

cols

rows

bestfit

Return Values

Returns TRUE on success.

Errors/Exceptions

Throws ImagickException on error.

Changelog

Version Description
2.1.0 Added optional fit parameter. This method now supports proportional scaling. Pass zero as either parameter for proportional scaling.

Коментарии

Here is an easy way to resize an animated gif : 

$picture = new Imagick('animated_gif.gif');

foreach($picture as $frame){
    $frame->scaleImage($width, $height);
}
2007-08-02 09:37:20
http://php5.kiev.ua/manual/ru/imagick.scaleimage.html
If anyone finds "The other parameter will be calculated if 0 is passed as either param. " to be a bit confusing, it means approximately this:

<?php
$im 
= new Imagick('example.jpg');
$im->scaleImage(3000);
?>

This scales the image such that it is now 300 pixels wide, and automatically calculates the height to keep the image at the same aspect ratio.

<?php
$im 
= new Imagick('example.jpg');
$im->scaleImage(0300);
?>

Similarly, this example scales the image to make it 300 pixels tall, and the method automatically recalculates the image's height to maintain the aspect ratio.
2009-06-16 11:38:46
http://php5.kiev.ua/manual/ru/imagick.scaleimage.html
When using the "fit = true" option, the image will only scale down, but never scale up:

<?php
$im 
= new Imagick('1600x1200.jpg');

$im->scaleImage(20001500true); // => 1600x1200

$im->scaleImage(1000500true); // => 666x500
?>
2009-07-23 05:57:39
http://php5.kiev.ua/manual/ru/imagick.scaleimage.html
Need to resize portrait and landscape images (and convert to 72ppi)? These will fit an area of 800x600 without distorting, no matter how tall or wide.

<?php
    $img 
= new Imagick($img_loc.$file);
   
$img->setImageResolution(72,72); 
   
$img->resampleImage(72,72,imagick::FILTER_UNDEFINED,1);
   
$img->scaleImage(800,0);
   
$d $img->getImageGeometry(); 
   
$h $d['height']; 
    if(
$h 600) {
   
$img->scaleImage(0,600);
   
$img->writeImage($resized_loc.$file);
    } else {
   
$img->writeImage($resized_loc.$file);
    }
   
$img->destroy();
?>
2012-11-08 23:50:20
http://php5.kiev.ua/manual/ru/imagick.scaleimage.html
Warning: this will blur your edges in possibly unexpected ways. For better control, use resizeImage, instead.
2014-03-15 17:34:48
http://php5.kiev.ua/manual/ru/imagick.scaleimage.html

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