Resize image using the URL

Hello,

I started a thread a while ago about resize an image to a container without the image losing its aspect ratio - link to the thread"

I tried to achieve this using CSS which I did manage to do. However, CSS didn’t seem to do it very elegantly and displays differently in different browsers.

So what I want to do is resize an image to its parent div size which is 174x217px. The image should remain good quality, resize quickly and not have any of the image overflowing or being cut off. I’ve seen many sites resizing the image by using the URL. The default example on this page is something i’m looking for here.

The url to the image would be something like this mywebsite.com/images/testimage.png?width=174&height=217

Any suggestions?

You can do it with GD or imagemagick; years ago I found a piece of code that would do it via the .htaccess file but that is long gone from my PC.

A couple of Imagemagick methods from memory is best to put these codes on separate pages and call with <img src=“php_code.php”>:


<?php 
$photo="sunflower.jpg"; 

$cmd = "convert $photo -thumbnail 200x200 ". 
" -unsharp 0.2x0.6+1.0 -quality 100 JPG:-"; 

header("Content-type: image/jpeg"); 
passthru($cmd, $retval); 
?>  

// There can not be any code before this:
<?php 
system("convert ../code/sunflower.jpg -resize 200x200 JPG:-"); 
?>

This was the website I found the .htaccess method code on.