Reputation: 5531
Im hitting a road block here. I have a dynamic site, where the user uploads images, and it displays it on the page. Thats all fine and dandy, but im sure we have all ran into the scenario where images of a non defined size can really mess up our graphical presentation by overflowing and pushing other elements. So, im wondering if there is a a way where you can set a defined size for an image (in my case height) and have the width just scale to retain proportions. Ive tried just setting the height attribute and no width, but that didnt display anything (like the width was set to 0). Any tips or help would be greatly appreciated.
Upvotes: 0
Views: 270
Reputation: 2832
Use Imagick to resize the image:
<?php
$thumb = new Imagick();
$thumb->readImage('myimage.gif');
$thumb->resizeImage(320,240,Imagick::FILTER_LANCZOS,1);
$thumb->writeImage('mythumb.gif');
$thumb->clear();
$thumb->destroy();
?>
Edit: to maintain the aspect ratio use scaleImage, set the value for the dimension you want to resize and 0 to the other dimension to maintain aspect ratio:
$im->scaleImage(0, 300);
Upvotes: 2