phMagick :: Resizing Images
By default phMagick will resize images if they are bigger than the specified measures because enlarging images always produces bad results (heavily pixelized images).
Proportional width & height resize
If you just specify one measure the image will be resized proportionally to the desired size
To 200px width :
//resing to fit a particuar width $phMagick = new phMagick('lipe.jpg', 'resize_porp_w.png'); $phMagick->resize(200); // the same as resize(200,0)
| Original Image | Transformed Image |
![]() |
![]() |
To 100px height :
// and to fit a particular height $phMagick = new phMagick('lipe.jpg'); $phMagick->setDestination('resize_porp_h.png') ->resize(0,100); // set width to 0 so that phMagick knows that the resize should // be done proportional to the height of the image // We can set the destination file name in the class instantiation or by // using the setDestination() function
| Original Image | Transformed Image |
![]() |
![]() |
Resizing to fit in a box
If you specify width and height the image will be resized to a size that bests fits the measures, it may not be the exact measures since aspect ratio will be maintained. If you set ExactSize = true then no attempt to maintain aspect ratio will be done and the image will have exactly the measures specified
Mantaining aspect ration
//fitting a 150x 150px box $phMagick = new phMagick('lipe.jpg'); $phMagick->setDestination('resize_porp_wh.png') ->resize(150,100);
| Original Image | Transformed Image |
![]() |
![]() |
Exact dimensions
// making it exactly 80 x 150px $phMagick = new phMagick('lipe.jpg'); $phMagick->setDestination('resize_dumb.png') ->resize(80,150,true);
| Original Image | Transformed Image |
![]() |
|
As you can see resizing to an exact size may produce streched images
Resize an image to an exact size mantaining aspec ratio
It's possible to resize an image to an exact size while mantaining the aspect ratio, internaly this is done by resising and croping the new image
Take note that this aproach is not 100% accurate, there are some extreme situations where the resulting image will not have the desired size
$p = new phmagick('source.png', 'destination.png'); $p->resizeExactly(133,100);
| Original Image | Transformed Image |
![]() |
![]() |





Olá Franco,
Parabéns pela classe phMagick, ela é realmente fantástica.
Eu estava procurando alguma coisa na internet pra servir de base pra eu montar uma classe própria, mas achei a sua tão completa que acho que vou usar ela própria.
Eu só estou com um problema pra redimensionar imagens GIF com animação, elas ficam zoadas.
Você sabe como resolver isso ou a sua classe ainda não dá suporte para animações?
Pois preciso exatamente disso, inclusive é o motivo de eu não utilizar a classe Imagick que é nativa do PHP.
Eu tentei da seguinte forma:
require(dirname(__FILE__) . '/phmagick.php');
$img = new phMagick('animacao.gif');
$img->setDestination('saida_animacao.gif')->resize(250, 250);
Abraços!
Olá Leonardo,
Pois o ImageMagick não é grande coisa a redimensionar gifs animados, pelo que li é preciso fazer primeiro um coalesce à imagem
e depois então fazer o resize
um abraço
Hello Nuno. Firstly the phmagick package is excellent and very useful (and given me some good ideas on using plugin classes). Thankyou!
I had a problem with the polaroid and reflection methods when altering an image already altered using the crop class. The polaroid image shifted partly off the canvas so it was only partly visible, the reflected image was only a portion of the width of the original.
Long story short, after some tinkering I replaced the following
$cmd .= ‘ ‘ . $p->getDestination() ;
with
$cmd .= ‘ +repage ‘ . $p->getDestination() ;
in phMagick_crop::crop wich seemd to work like a charm.
I thought you may find it useful (although I haven’t fully tested that it doesn’t break anything else, my fixes usually do!)