Page 1 of 1

What is wrong with my shadow command?

Posted: 2007-04-04T15:54:13-07:00
by Dekker Dreyer
I'm trying to build an image. The image consists of a floor, a wall, an object on the wall, and the object's drop shadow cast on the wall. I've tried following various examples of using +clone to do the shadow but I get strange results. Maybe it's the way I'm building the image.

I want to clarify that I want the wall image stacked on top of the floor image. The wall has transparency, the floor does not. I'm also modulating the wall image.

So this is my command line:

convert floor.jpg ( wall.png -modulate 100,100,10 ) -composite
( object.jpg -geometry 400x250+10-150 -gravity center -background black -shadow 70x10 ) -composite
( object.jpg -geometry 400x250+0-160 -gravity center ) -composite
output.jpg

I've tried doing -shadow 70x10+10+10 but it is never visible. The only way I can see the shadow is by shifting its geometry with respect to the object. However, as the object changes size and shape so does the shadow.

Can anyone offer some suggestions on how I can improve this?

Re: What is wrong with my shadow command?

Posted: 2007-04-04T16:44:07-07:00
by anthony
You make like to give use the images you are using, so we can try out the command ourselves.

In any case -shadow requires the image to have a alpha or transparency channel. A JPEG image does NOT have such a channel. Add -matte immedaitally afetr reading the JPEG image.

Re: What is wrong with my shadow command?

Posted: 2007-04-05T04:45:48-07:00
by Dekker Dreyer
Ok, so I tried this

convert floor.jpg ( wall.png -modulate 100,100,10 ) -composite
( object.jpg -matte -geometry 400x250+10-150 -gravity center
+clone -background black -shadow 70x10+10+10 +swap ) -composite
output.jpg

and a few variants but nothing came out looking as I would expect.

Here are the images:

http://img100.imageshack.us/img100/8672/floorgy7.jpg
http://img297.imageshack.us/img297/8932/objectoc9.jpg
http://img297.imageshack.us/img297/4340/walldc9.png

Thanks for helping!

Re: What is wrong with my shadow command?

Posted: 2007-04-05T08:06:43-07:00
by Dekker Dreyer
Ok, I am able to use the shadow command, but my shadow changes depending on the resolution of the object.

http://img249.imageshack.us/img249/2751/22en4.jpg (22)
http://img124.imageshack.us/img124/8984/23zd6.jpg (23)
http://img100.imageshack.us/img100/8672/floorgy7.jpg (floor)
http://img297.imageshack.us/img297/4340/walldc9.png (wall)

convert ( floor.jpg ( wall.png -modulate 100,100,60 ) -composite )
( ( 22.jpg -geometry 155x155+0-160 -gravity center )
( +clone -background black -shadow 70x10+20+20 )
+swap -background none -mosaic ) -composite out.jpg

As I put in 22.jpg or 23.jpg the shadow changes size. In addition, the shape of the white square changes size. What am I doing to cause those to change size? 23 looks correct, 22 looks wrong. What can I do so that swapping out 23 for 22 doesn't change the way it looks?

Re: What is wrong with my shadow command?

Posted: 2007-04-06T04:19:22-07:00
by anthony
The +swap should be OUTSIDE the parenthesis.

That is when parenthesis end, the resulting images is added to the end of the normal outer image squence, You can then re-order that sequence with +swap and then compose them together usinf -flatten and -mosaic.

I suggest you take smaller steps and try to understand the examples in IM examples a little more. Think in terms of 'lists of images' rather than individual images.

Noet that the -gravity center is for the composite, so you should put it with that operation.

This works for me (direct display rather than save to file)

Code: Select all

convert floor.jpg \( wall.png -modulate 100,100,60 \) -composite \
         \( \( 22.jpg -geometry 155x155+0-160 -gravity center \) \
            \( +clone -background black -shadow 70x10+20+20 \) \
            +swap -background none -mosaic \) \
         -gravity center  -composite    miff:- | display -

Re: What is wrong with my shadow command?

Posted: 2007-04-06T12:03:34-07:00
by Dekker Dreyer
Ok, thanks. I understand about the swap now. However, I still have the same problem with the different shadows and image sizes.

Image

Image

Both the white box, and the depth of the shadow, are different with the different 22.jpg and 23.jpg files. The geometry command is applied directly to the image, then I clone that resized image for the shadow. I don't understand why the frame on the wall would change size. I want the white square to be 155x155, and then a shadow to extend, say, 10 pixels. I want that to be the case no matter the pixel size of the white square image. I thought that putting the 22.jpg and -geometry into their own parenthesis would fix that, but it doesn't.

The only visible difference should be the text in the white box, not the size and shadow depth.

Can you point out what I'm doing wrong here?

Re: What is wrong with my shadow command?

Posted: 2007-04-07T05:43:14-07:00
by anthony
It should be the same. -geometry however is a very strange legacy operator,
that may have problems because of this historical baggage. IE you may have found a bug.
I'll have to experiment to find out.

In the mean time Try seperating the -geometry into two. make the first a -resize (seeing as you already had parenthesis (whcih was not needed for -geometry, but is for -resize)
and then add the -geometry {offset} just before the -composite which uses that offset.

Re: What is wrong with my shadow command?

Posted: 2007-04-07T08:06:01-07:00
by Dekker Dreyer
Ah! Beautiful! That did exactly what it was supposed to do. Thanks anthony for your time and patience.

Re: What is wrong with my shadow command?

Posted: 2007-04-08T02:49:52-07:00
by anthony
No problem. I would suggest that you try to find time to look through IM Examples,
Particualrly 'Basics' which explains how it all fits together in terms of 'lists of images'.

My one current problem is trying to allow the user to define two separate 'lists' of images
on a command line that only has one 'list'. (Alpha Composition of Animations)

I have one solution that appears to work well, and am trying to write up IM examples and fine turn its functionality against peoples needs.

Re: What is wrong with my shadow command?

Posted: 2007-04-08T08:58:27-07:00
by Dekker Dreyer
I spent quit a bit of time looking at examples. I was proud of myself to making it as far as I did. I find few pages that actually explain why the sequence on the command line is the way it is. Man page is a bit lacking, the manual is incomplete, and almost all of the web examples I saw for composites didn't use the convert command.

Re: What is wrong with my shadow command?

Posted: 2007-04-08T20:14:42-07:00
by anthony
The problem was the use of composites in 'convert' was only added in IM v6. Before that all composition either needed a separate 'composite' command, OR a miss-use of the '-flatten' option. Neither very nice.

Note, this weekend I am just adding Mutli-Image composition abilities for composing image sequneces and animations. IM examples and manual for this has not been updated yet.

The main IM manuals is 'dry' as like most UNIX man pages, it really is a reference summery of commands, not a how to use manual. This is what IM examples is doing, filling the gap between begineers who just want to know 'how to' and experts who want ot lookup 'specifics'.