Ask your JavaScript questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Old code crops images, but doesn't resize (using Image Magick) JavaScript


This is [[LINK href=""]]the code on github.[[/LINK]]

This is [[LINK href=""]]it live on a site[[/LINK]]

When I test it, the images get cropped to scale, but not resized.

It's designed to crop and resize images to 18 typical banner sizes. <em>It used to do this</em>, but I let it sit for a couple years. I suspect some specification with my host (Dreamhost shared hosting) has changed which prevents it from working.

In the home folder of the server is something like:

I know that ImageMagick is out of date, though I'm also not sure it's being called from there and not the Dreamhost installation.

I'd like to get the resizing function working again.

Answers (1)


dbranes answers:

Hi Steve

From the github code it looks like you are using <strong>mogrify</strong> on the server to crop and resize the images.

Try to run <strong>mogrify</strong> in the commandline with the same parameters as you find in the <em>Imagick::resizeImageWithQuadraticFilter()</em> method, for example:

/usr/bin/mogrify -adaptive-resize 400x300 -filter Quadratic test.jpg

This command is working on my Linux install.

You can check the ImageMagick version with:

/usr/bin/mogrify -version

You can also try the <strong>convert</strong> command:

/usr/bin/convert orginal.jpg -adaptive-resize 400x300 -filter Quadratic test.jpg

Try also to echo the output of $convert with:

echo "<pre><h2>DEBUG:</h2>".$convert."</pre>";

just before <em>exec($convert);</em> in the methods <em>Imagick::resizeImageWithQuadraticFilter()</em> and <em>Imagick::cropImage()</em>.

Steve Lambert comments:

Thanks for jumping in. I tested mogrify on the command line with an image that was 300x100 like so:

$ /usr/bin/mogrify -adaptive-resize 200x100 -filter Quadratic test300x100.jpg

And I ended up with an image that was 200x67 – which is fine and as expected right? Not sure why it's not working with the code on github though.

I ran this:

$ /usr/bin/mogrify -version
Version: ImageMagick 6.6.0-4 2012-05-02 Q16
Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC
Features: OpenMP

So that image magick folder on my server probably isn't being called from right?

What next?


dbranes comments:

Try to replace:

public function resizeImageWithQuadraticFilter($NewWidth, $NewHeight) {
$geometry = $Width.'x'.$Height;
$convert=$location . ' -adaptive-resize ' . $geometry . ' -filter Quadratic ' . escapeshellarg($this->tempPath);
exec ($convert);
return true;


public function resizeImageWithQuadraticFilter($NewWidth, $NewHeight) {
$geometry = $NewWidth.'x'.$NewHeight;
$convert=$location . ' -adaptive-resize ' . $geometry . ' -filter Quadratic ' . escapeshellarg($this->tempPath);
exec ($convert);
return true;

dbranes comments:

i.e. replace

geometry = $Width.'x'.$Height;


$geometry = $NewWidth.'x'.$NewHeight;

in the <em>Imagick::resizeImageWithQuadraticFilter()</em> class method.

<strong>ps:</strong> We want to match the function input parameters: <em>resizeImageWithQuadraticFilter($NewWidth, $NewHeight)</em>.

Steve Lambert comments:

That worked. Fantastic. Thank you!