I have a command that I can run on the command line to tilt-shift an image using Imagemagick:
convert \( myimage.jpg -gamma 0.75 -modulate 100,130 -contrast \) \( +clone -sparse-color Barycentric "0,0 black 0,%h white" -function polynomial 4,-4,1 -level 0,50% \) -compose blur -set option:compose:args 5 -composite myimage.jpg
I’d like to be able to reproduce the effect of this command using PHP’s imagemagick library. The first parts of the command are easy to reproduce, but I’m having trouble figuring out sparse-color and the arguments after it. So far I have:
$image = new imagick("myimage.jpg")
$image->gammaImage(0.75);
$image->modulateImage(100,130,100);
$image->contrastImage(1);
Thanks!
I am assuming that you are referring to the examples found here:
http://www.imagemagick.org/Usage/photos/
With that said, I have been trying to accomplish the very same thing with PHP Imagick. I am using PHP Imagick 3.0.1 and ImageMagick 6.7.4-4 2012-01-09 Q16 in Linux.
It appears that the blur composite mode is undocumented. I found it by looking through the ImageMagick source under
magick/composite.hon line88.This code accomplishes what you are looking for:
If you require more blur, simply change
compose:argsto10or something. One thing I figured out was that I had to set the option before I created/loaded anything into the wand itself.I could not get the
SparseColorImage()function to behave as it does on the command line, although I am sure that someone else could contribute that part if they figure it out. The above is enough for my needs.EDIT: Upon further inspection of the images generated I noticed that even the black parts of the blur map were being blurred. After some searching it appears that this stems from a bug introduced in ImageMagick. I switched to version 6.7.8-1 2012-07-05 Q16 and the blur map now appears to be working. If you notice unwanted blurring with the blur composite I suggest you upgrade your ImageMagick.