The experimental ImageMagick code in the function imageapi_imagemagick_image_definecanvas() appears not to handle the "Resize canvas under image (possibly cropping)" option. I've used the -extent ImageMagick option to implement this. I have no idea if it works in all instances, but it works for me when I want to force images to a fixed size without changing the aspect ratio. The code also supports transparency.
My implementation is:
function imageapi_imagemagick_image_definecanvas(&$image, $action = array()) {
$targetsize = $action['targetsize'];
$RGB = $action['RGB'];
$backgroundcolor = $RGB['HEX'] != '' ? '#'. $RGB['HEX'] : 'None';
# TODO needs work.
#
$background = " -background '{$backgroundcolor}' ";
$crop = " -crop '{$targetsize['width']}x{$targetsize['height']}-{$targetsize['left']}-{$targetsize['top']}!' ";
$draw = " -draw '";
$draw .= " fill '{$RGB['HEX']}' polygon 0,0 {$targetsize['width']},0 {$targetsize['width']},{$targetsize['height']} 0,{$targetsize['height']} ";
$draw .= " ' ";
#$draw .= " -composite ";
$draw .= " +repage ";
$extent = " -extent '{$targetsize['width']}x{$targetsize['height']}-{$targetsize['left']}-{$targetsize['top']}!'";
if ($action['under']) {
$compose = " $background $crop $extent ";
} else {
$compose = " $background $crop $draw ";
}
$image->ops[] = $compose;
return TRUE;
}
Comments
Comment #1
dman commentedsounds good
Comment #2
tajabosc commented@Jorrit I tried your code with success using imagemagick, so i made a patch to the module to facilitate further testing.
The file to be patched is canvasactions.inc
Daniele
Comment #3
dman commentedCool, works for me. This is now in DRUPAL-6--2-0 dev
Comment #5
jami3z commentedSorry to reopen, didn't know if to create a new issue but this does not work for me using 6.x-2.x-dev (which has the patch applied). I have tried enabling/disabling the module a few times and clearing caches but the warning "Define Canvas not currently supported by using imagemagick. This effect requires GD image toolkit only." still shows and doesnt matter what I set the background HEX to the preview image always shows black.
I have the following installed
- imagecache 6.x-2.x-dev
- imagecache_actions 6.x-2.x-dev
- imageapi 6.x-1.8 (using ImageMagick)
Comment #6
jami3z commentedI also have tried the #2 patch on a seperate installed Imagecache_actions 6.x-1.7 version and it did not work for me. Are there any other version requirements for imagecache or imageapi for this to work?
Comment #7
tajabosc commented@jamienotweet
I have the following modules enabled:
-ImageAPI 6.x-1.8
-ImageAPI ImageMagick 6.x-1.8
-ImageCache 6.x-2.0-beta10
-ImageCache UI 6.x-2.0-beta10
-Imagecache Canvas Actions 6.x-1.7
Haven't tested with -dev versions of ImageCache and Imagecache Actions
Comment #8
Andrey Zakharov commenteddunno why you are using draw-fill-rectacle construction but there is a command in ImageMagick to define canvas:
convert -size 100x100 xc:black test.pngdo the trickComment #9
dman commentedI've been testing these, and none of them are working quite right for me so far.
@Andrey Zakharov
The 'fill' was being used in cases where $action['under'] is false. In those cases the expected result is a solid canvas over top of the image. That at least made sense, although it's seldom used in examples so far, it is handy as an early step in compositing.
Your version does a better job with the color, but still seems to fail to do the normal 'make the canvas bigger by padding it with a background' effect we expect. just -crop does not upsize for me.
I'm starting to think there are issues with imagemagick versions, because I just can't get the last two parameters to -extent to have any of their documented effect (offset positioning).
-extent '300x350-10-10'I have
ImageMagick 6.2.8 06/11/08on the OSX desktop, and apt-get is claiming it's the latest version - which I doubt.Upgrading through other means - recompiling piles of stuff - seems to be hard as it triggers rebuild of a dozen other important dependencies that make me nervous.
Comment #10
dman commentedHUGE fixes. Took me all weekend, but I now have close-to-satisfactory updated support for imagemagick!!
define canvas, overlay and more now work.
in -dev 2.x
Comment #11
Jorrit commentedWhen will there be a release of the 6.x-2.x branch?
Comment #12
fietserwinFixed in 7.x-1.x-dev.
I ended up using the -extent option, which looked the best fit to me.
Comment #14
mikeytown2 commentedRe-rolled patch in #2 for 6.x-1.x-dev
Comment #15
fietserwinComment #16
nelslynn commentedAny chance to commit this patch to the Recommended releases version? The issue remains using 7.x-1.4
Comment #17
osopolarRe-rolled patch in #14 for 6.x-1.x-dev
Couldn't get interdiff working on this. I left out following changes:
No need for the if statement with no instructions.
No need for this comment as git message points to the issue.
Comment #18
osopolarPlease review again.
Comment #20
fietserwinIgnore #19 ... nothing was committed.
Comment #21
fietserwinD6 EOL. This module's D6 issues already haven't received any attention for over a year. Closing them all unconditionally now.