ImageAPI 6.x-1.6
ImageCache 6.x-2.0-beta10
Imagetoolkit ImageMagick

My users upload images in jpg format (mostly). I wanted to make a thumbnail with the polaroid effect of the imagemagick.
I converted imagecache_sample.png to jpg in the default/files directory because I wanted to see the action on jpg file. Then I renamed it back to imagecache_sample.png. Testing with "file imagecache_sample.png" gives "imagecache_sample.png: JPEG image data, JFIF standard 1.01". Thats ok!

The actions I added are:
* Scale and Crop (150x150 pixels)
* Custom action:

_imageapi_imagemagick_convert($image->source, $image->source, array(0 => "-bordercolor snow2 -background black -polaroid -0"));
return $image;

Although the Scale and Crop is before Custom action in preset list, in debug messages I get:

ImageMagick command: /usr/bin/convert 'sites/default/files/imagecache_sample.png' -bordercolor snow2 -background black -polaroid -0 -quality '100' 'sites/default/files/imagecache_sample.png'

ImageMagick command: /usr/bin/convert 'sites/default/files/imagecache_sample.png' -resize 150x172! -crop 150x150+0+10! -quality '100' 'sites/default/files/imagecache/photo-teaser/imagecache_sample.png'

Finally, all I want is to make a thumbnail, apply the polaroid effect and convert the result to png.

Any ideas?

CommentFileSizeAuthor
#2 imagecache_preset_result.png14.58 KBauris
#2 result_thumb.png32.41 KBauris

Comments

dman’s picture

Can you point at the documentation that told you to run "_imageapi_imagemagick_convert" ? Because it's totally wrong and should be corrected.
Functions starting with _ are nominally private, and are not expected to be called from outside the module code.

The way imagecache, imagepi, both GD and imagemagick work is by stringing together a bunch of actions one after another, in a pipeline. Not by doing one transform, saving the results, then doing the next. imagemagick_convert is the thing that gets called at the end and strings all the operations together. Calling it in the middle is just not going to work.

I don't use imagemagick, but I know from looking at the code that it just tags on 'operations' into the $image->ops[] array. See how any of the other imageapi_imagemagick_image_{action}() functions do their thing to insert actions into imagemagick processes.
Those operations are imagemagick phrases or directives that all get glued into a string at the end, the imagemagick pipeline. You do NOT enter a full commandline, nor call any functions that have side-effects.

I imagine that what you actually want to do in the customactions code is just

$image->ops[] = "-bordercolor snow2 -background black -polaroid -0 -quality '100'";
auris’s picture

StatusFileSize
new32.41 KB
new14.58 KB

The idea to use _imageapi_imagemagick_convert was taken from http://drupal.org/node/460132. I see now that it's wrong. Your tip is great! Thanks!

My problem now is this: Although the imagecache preset example looks exactly as I want (see imagecache_preset_result.png), the result thumbnails have a black border around them (see result_thumb.png). As I wrote above the source files are jpg. I thought to add a Change File format and Convert to: png settings, but it didn't solve the problem.

dman’s picture

You've intentionally set "-background black"
Which I would guess mean you wanted a black background.
If not, then why?
Also, the '-quality 100' is probably unneeded for a thumbnail.

auris’s picture

The -background -black option is for the photo shadow.
The problem is that the thumbnail remain in jpg format, so there is no transparency to the shadow and gets a solid black border.

Is there any way to convert the thumb and save it to png?

dman’s picture

using GD, I've got the 'convert file format' action. Also the 'flatten transparency' action. But not supported (or attempted) in Imagemagick.
If you can find the way to do that in the imagemagick docs, please let me know.

dman’s picture

Status: Active » Fixed

I think this is as fixed as it will ever be.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.