dakanji/Gallery2 — Issue #10: ImageMagick crop operation fails (followup) - ID: 1106718
Author: dakanji
Created: 2012-03-04 20:34:50+00:00
State: open
Labels: bug

http://sourceforge.net/tracker/?func=detail&aid=1106718&group_id=7130&atid=107130
==================================

ImageMagick seems to apply its "-crop" operation
_after_ a "-geometry". This results in wrong
coordinates for cropping and therefore a wrong or
broken thumbnail (when using the thumbnailing Java
applet for example).

The trick is to use _percentage_ coordinates. The
developer seemed to overlook that ImageMagick can use
these and converted everything to pixels.
I just added a '%' sign to the crop-geometry and
everything was fine.

here an except from "ImageMagickToolkit.class"

case 'crop':
/* source dimensions are required to
convert from percentages to pixels
$pixelX = round($parameters[0] / 100 * $width);
$pixelY = round($parameters[1] / 100 *
$height);
$width = round($parameters[2] / 100 * $width);
$height = round($parameters[3] / 100 *
$height);
towi: nope! not needed! just add a '%' to
the geometry. */

$cmd = 'convert';
if (is_int($i = array_search('-scale',
$transform))) { /*towi: was '-size'. wrong! */
array_splice($transform, $i, 2);
}
$transform = array_merge($transform,
array('-crop',
sprintf('%sx%s+%s+%s%%', //towi: added last '%' sign
to stay in percent-topology

$parameters[2],$parameters[3],$parameters[0],$parameters[1])));
//towi: $width, $height, $pixelX, $pixelY)));
break;

By the way: you have to replace all "-size" with
"-scale"/"-resize", because "-size" means a totally
different thing in ImageMagic (it is used to read raw
images).

tschau, towi.

Submitted:
Torsten Will ( towi ) - 2005-01-21 06:13:53 PST

Priority:
5

Status:
Open

Resolution:
None

Assigned:
Nobody/Anonymous

Category:
NoneGroup:
Gallery 2

Visibility:
Public