May 02, 2003

The Making-Of a Blog: dropping shadows

Today I wanted to be able to drop shadows on photos. I did not succeed completely (or “automaticaly” must I say) maybe because of a bug in ImageMagick conjure command line tool. I have submited my problem to the "Magick-users" mailing-list and I hope to have an answer soon...

But here follows my story... I first discovered thanks to the serendipity goddess Raymond Penners' home page who wrote a script called Photo Stack for The GIMP. This script uses the Script-Fu extension mecanism incorporated in The GIMP to process an image – as a script-fu, it is written in scheme... This effect is very original cos it does not only stick a border to an image, it simulates a pile of photos. Here is an example:

In order to understand this script, you need to be quite confortable with The GIMP and to read The GIMP API Documentation. What is hard is not this API but the lisp-way of writing scripts in The Gimp! However it seems the day is coming when we will be able to use The GIMP in script like all other Unix tools, according to this answer to a message about recording Gimp actions in the "Gimp-developer" mailing-list. Here is what we can read on the GNOME Bug Tracker (powered by Bugzilla):


This feature is on the TODO list, but several important changes are
necessary before it can be implemented. The user interface must be
separated from the core, and all actions performed via the GUI must
result in corresponding PDB calls. Once this is done, then all
actions invoked through the menus, all brush strokes, selections and
other actions will go through the PDB where they can be caught and
recorded in a file. Then it should be easy to export the sequence
of actions as a Script-Fu or Perl-Fu script.

This feature will probably be implemented in Gimp 2.0.


Wooo... I would be very happy to be able to write XML descriptions of processings to do on images with The GIMP!
Ok, I go on. I decided to stop studying this script (I will be back to it when I will be able to drop shadows with ImageMagick, converting it to a PerlMagick script maybe).

So I decided to explore ImageMagick mailing-lists to learn more about the conjure tools and maybe to find information about dropping shadows. The main answer is that conjure is really not wide diffused in the ImageMagick community and there is in fact no documentation. For example I learned that you can compose images (XML scripting version of the composite command line tool) in this thread about handling groups of images in a MSL file; there are other tips in this thread dealing with undocumented functions of conjure.

On the effect sire, I first found this thread about dropping shadows with PerlMagick but the result did not look very good. Hopefuly searching on Google I found in the "Gimp-user" mailing-list this message describing how to drop shadows with ImageMagick “like in Adobe Photoshop”; but the explanation was a bit too Gimp-oriented. I was finaly helped by the "Magick-users" mailing-list with the conclusion of a thread about dropping shadows in ImageMagick, answering this question describing the steps needed for this effect:


  1. get the original image;

  2. create a black image having the same size than the original;

  3. add a 5x5 blur to the black image;

  4. combine the original image over the black one offset right 5 down 5;

  5. set the background color of the result image.


Using options from ImageMagick, the only difficult part is the 5x5 blur. In fact, after producing the black image, we must add a 20x20 white border, apply a 0x3 gaussian blur (radius=0, sigma=3) and shave the image by 15x15: we get a (20x20)-(15x15)=5x5 blur!
My actual MSL script doing this job and submitted to the "Magick-user" mailing-list is here (with different parameters for the blur: radius=0, sigma=4):

<?xml version="1.0" encoding="UTF-8"?>
<group id='photo' >
<image id='img' >
<read filename="%[f].jpg" />
<border fill="white" width="10" height="10" />
<write filename="tmp_img.miff" />
</image>
<image id='tmp'>
<read filename="tmp_img.miff" />
<get width="base-width" height="base-height" />
</image>
<image id='shadow'
   size="%[base-width]x%[base-height]" color="black" >
<border fill="white" width="20" height="20" />
<blur radius="0" sigma="4" />
<shave geometry="15x15" />
<write filename="tmp_shadow.miff" />
</image>
<image>
<read filename="tmp_shadow.miff" />
<composite image="img"
   compose="over" gravity="center" geometry="-4-4" />
</image>
<write filename="%[f]_photo.jpg" />
</group>

Is does not work cos the value "center" for the attribute gravity seems to be not processed.
Finishing the job with a little fix batch script, I get:

composite -gravity "center" -geometry "-4-4" -compose "over"
   tmp_img.miff tmp_shadow.miff %1_shadow.jpg
mogrify -rotate "-5" %1_shadow.jpg
mogrify -resize "200x" %1_shadow.jpg


Cool, isn't it?... and very close to what I wanted in my previous tutorial: I lack only a wider and lighter shadow! You can see too that I have nomore problems with aliasing cos I make the resizing after the skewing. For example, here is the old photo effect with a new little border of 1 pixel and a white border of 20 pixels:

This is the end for the moment. I am waiting for an answer to know if I am stupid or if it is conjure which is bugged. I need too to investigate a recent articles on "LinuxWorld.com", entitled “Adding eye candy to your desktop” and dealing with dropping shadows onto icons with PerlMagick.
After this affair, I will publish complete batch files and scripts, documented and with more configuration parameters.

Posted by Jean-Philippe on May 02, 2003 at 03:19 AM 27 Comments, 922 TrackBacks

Filed in making-of, my website

Post your own.

Comments

25

no comment

Posted by surya on February 06, 2009 at 08:23 AM (Spam: 8%)

Post a comment
Security Code Check





Remember personal info?


Entries by category

Entries by month