PHP 5.6.16 is available


(PECL imagick 2.0.0)

Imagick::scaleImageScales the size of an image


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.

Nota: O comportamento do parâmetro bestfit mudou no Imagick 3.0.0. Antes desta versão ao informar dimensões 400x400 numa imagem de 200x150 não causaria alterações. No Imagick 3.0.0 e posteriores a imagem seria escalada para 400x300 por ser o "melhor ajuste" entre as dimensões. Se bestfit é informado tanto a altura como comprimento devem ser informados.





Valor Retornado

Retorna TRUE no sucesso.


Lança ImagickException em caso de erro.


Versão Descrição
2.1.0 Added optional fit parameter. This method now supports proportional scaling. Pass zero as either parameter for proportional scaling.


Exemplo #1 Imagick::scaleImage()

function scaleImage($imagePath) {
$imagick = new \Imagick(realpath($imagePath));
header("Content-Type: image/jpg");


add a note add a note

User Contributed Notes 6 notes

benford at bluhelix dot com
6 years ago
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:

= new Imagick('example.jpg');
$im->scaleImage(300, 0);

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.

= new Imagick('example.jpg');
$im->scaleImage(0, 300);

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.
octave at web dot de
6 years ago
When using the "fit = true" option, the image will only scale down, but never scale up:

= new Imagick('1600x1200.jpg');

$im->scaleImage(2000, 1500, true); // => 1600x1200

$im->scaleImage(1000, 500, true); // => 666x500
vincent dot hoen at gmail dot com
8 years ago
Here is an easy way to resize an animated gif :

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

foreach($picture as $frame){
    $frame->scaleImage($width, $height);
clickconvert at gmail dot com
3 years ago
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.

= new Imagick($img_loc.$file);
$d = $img->getImageGeometry();
$h = $d['height'];
$h > 600) {
    } else {
agamemnus at flyingsoft dot pw
1 year ago
Warning: this will blur your edges in possibly unexpected ways. For better control, use resizeImage, instead.
peter at icb dot at
6 years ago
If using the fit-parameter this function sometimes seems not to work when one of the two sizes (width or height) is the same size as the image has. For example:

= new Imagick('800x480.jpg');
$image->scaleImage(640, 480, true);

// $image is still 800x480

You have to calculate the new sizes yourself and use false for $fit in this case.
To Top