Clone centering & shadowing over image background

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
motumbo
Posts: 16
Joined: 2011-07-26T12:56:12-07:00
Authentication code: 8675308

Clone centering & shadowing over image background

Post by motumbo »

I'm trying to center on image (-thumbnail) over a background and apply a -shadow and -rise (at 50%) on a single (convert) command-line

Here an example of what I'm trying (not working):

convert sky.png \( ball.jpg -thumbnail 500x500 \( +clone -background black -shadow 30x12+3+3 \) +swap \( -clone -2 -raise 10 -channel A -evaluate multiply .5 +channel \) \) -mosaic output.jpg

I've attached an example of the output I'm trying to get.

Image

source images:
http://www.divicast.com/photos/sky.png
http://www.divicast.com/photos/ball.jpg
Last edited by motumbo on 2011-09-21T17:27:59-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Clone centering & shadowing over image background

Post by fmw42 »

can you post your input images so others can test with them?
motumbo
Posts: 16
Joined: 2011-07-26T12:56:12-07:00
Authentication code: 8675308

Re: Clone centering & shadowing over image background

Post by motumbo »

done, thanks!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Clone centering & shadowing over image background

Post by fmw42 »

Note IM -shadow will not be all around your image. see http://www.imagemagick.org/Usage/thumbnails/#shadow

For such a shadow effect, you probably need to use -blur from a mask and then work with that.

I will try to come up with a solution as soon as I can get to it (later tonight or tomorrow). Others are welcome to do so before me.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Clone centering & shadowing over image background

Post by fmw42 »

This should do something like what you want.



# first line read images
# second line -- create black image size of sky.png
# third line -- create white image size of ball.jpg
# fourth and fifth line -- create mask image -- composite white image over center of larger black image and blur by sigma=15, then
# recomposite white image over center again to cover over blur inside the smaller area, leaving blur outside the smaller area
# sixth line -- add 25 pixel raised area in ball image
# seventh line -- composite raised ball image over mask image
# eighth line -- delete temps and swap last two image so mask is last, then composite using mask

convert sky.png ball.jpg \
\( -clone 0 -fill black -colorize 100% \) \
\( -clone 1 -fill white -colorize 100% \) \
\( -clone 2 -clone 3 -gravity center -compose over -composite -blur 0x15 \
-clone 3 -gravity center -compose over -composite \) \
\( -clone 1 -raise 25 \) \
\( -clone 4 -clone 5 -gravity center -compose over -composite \) \
-delete 1,2,3,5 +swap -compose over -composite \
sky_ball.jpg

50% reduced result:
Image

Or if you want to control the darkeness of the shadow effect:


convert sky.png ball.jpg \
\( -clone 0 -fill black -colorize 100% \) \
\( -clone 1 -fill white -colorize 100% \) \
\( -clone 2 -clone 3 -gravity center -compose over -composite -blur 0x15 \
-clone 3 -gravity center -compose over -composite \) \
\( -clone 1 -raise 25 \) \
\( -clone 4 -evaluate multiply 0.5 -clone 5 -gravity center -compose over -composite \) \
-delete 1,2,3,5 +swap -compose over -composite \
sky_ball2.jpg

50% reduced size:
Image
motumbo
Posts: 16
Joined: 2011-07-26T12:56:12-07:00
Authentication code: 8675308

Re: Clone centering & shadowing over image background

Post by motumbo »

Amazing, it's a perfect example!!

I'm now trying to add a gradient over the ball.jpg with something like:

\( -size XXxXX gradient:white-#222222 -distort SRT -60 -compose Multiply \) \ and so on.....

Where the gradient is the exact size of ball.jpg (-clone 1).

Is there any way to use -clone 1's size as -size for the gradient?

Thanks again!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Clone centering & shadowing over image background

Post by fmw42 »

motumbo wrote:Amazing, it's a perfect example!!

Is there any way to use -clone 1's size as -size for the gradient?

Thanks again!
Currently not like I used the image sizes to create the white and black images. You cannot do that for gradients at this time. I believe it is planned for IM 7.

However there is a way using -fx

convert someimage -fx "i/(w-1)" result

result will be a horizontal gradient with black on the left and white on the right which is the size of someimage

see http://www.imagemagick.org/Usage/canvas/#gradient_fx
motumbo
Posts: 16
Joined: 2011-07-26T12:56:12-07:00
Authentication code: 8675308

Re: Clone centering & shadowing over image background

Post by motumbo »

Thanks again! I think I'm almost there. I was trying to play with -shadow but it doesn't seem to respect the X (+100) Y (+100) positioning...

convert sky.png ball.jpg \
\( -clone 1 -gravity center \) \
\( -clone 2 -background black -shadow 100x1+100+100 \) \
\( -clone 3 -clone 2 -compose over -composite \) \
-delete 1,2,3 -compose over -composite \
output.jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Clone centering & shadowing over image background

Post by fmw42 »

see http://www.imagemagick.org/Usage/blur/#shadow

But note that -shadow will not put a dark area around the whole image, but only on two sides. It also needs a transparent background.\

I thought you wanted the dark area all around as in your example image. If not, be more specific. Once we know exactly what you want for the result or see some example, then we can try to help again.
motumbo
Posts: 16
Joined: 2011-07-26T12:56:12-07:00
Authentication code: 8675308

Re: Clone centering & shadowing over image background

Post by motumbo »

-shadow is actually working just fine for me (output attached) but I want to be able to move the X & Y positioning of the shadow in relation to the ball.jpg, and that doesn't seem to be working as expected. In this case the shadow should be 100pixels south and east and not centered.

convert sky.png ball.jpg \
\( -clone 1 -gravity center \) \
\( -clone 2 -background black -shadow 100x10+100+100 \) \
\( -clone 3 -clone 2 -compose over -composite \) \
-delete 1,2,3 -compose over -composite \
output.jpg

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Clone centering & shadowing over image background

Post by fmw42 »

try this:


convert sky.png ball.jpg \
\( -clone 1 -background black -shadow 100x10+10+10 \) \
\( -clone 1 -clone 2 +swap -background none -layers merge +repage \) \
-delete 1,2 -gravity center -compose over -composite sky_ball3.jpg

please see http://www.imagemagick.org/Usage/blur/#shadow for examples of how to create shadows


50% reduced size:
Image
motumbo
Posts: 16
Joined: 2011-07-26T12:56:12-07:00
Authentication code: 8675308

Re: Clone centering & shadowing over image background

Post by motumbo »

I'm still having an issue with the positioning as the -gravity center is now affecting the whole merged layer (ball and shadow) instead of the ball.jpg only:

see:

convert sky.png ball.jpg \
\( -clone 1 -background black -shadow 100x10+100+100 \) \
\( -clone 1 -clone 2 +swap -background none -layers merge +repage \) \
-delete 1,2 -gravity center -compose over -composite sky_ball3.jpg

unless I'm missing something I don't see this issue addressed on the examples

thanks for all the help!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Clone centering & shadowing over image background

Post by fmw42 »

Please explain what it is you want for the result. Be very specific or show an example. I am having trouble understanding what it is you want to change or do! What do you want centered and what do you want more offset? Or do you want both offset? Again I am having trouble understanding what you want for the result.

The best way to debug is to put in -write tmpX.png for X=1, 2, ... at the end of each parenthesis . Then look at these images and see what is happening. Then think about what you want to be different or what is not working the way you expect.
motumbo
Posts: 16
Joined: 2011-07-26T12:56:12-07:00
Authentication code: 8675308

Re: Clone centering & shadowing over image background

Post by motumbo »

Here you have an (extreme) example of the result I'm looking for. That means that ball.jpg is fully centered and I need to be able to adjust the offset of the shadow without moving the ball.jpg. Let me know if this makes sense.

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Clone centering & shadowing over image background

Post by fmw42 »

Just adjust the offset. This works for me on IM 6.7.2.7 Q16 Mac OSX Tiger. What version of IM are you using?

convert sky.png ball.jpg \
\( -clone 1 -background black -shadow 100x10+100+100 \) \
\( -clone 1 -clone 2 +swap -background none -layers merge +repage \) \
-delete 1,2 -gravity center -compose over -composite sky_ball4.jpg

If it does not, then you could try:


convert sky.png ball.jpg -respect-parenthesis \
\( -clone 1 -background black -shadow 100x10+100+100 \) \
\( -clone 1 -clone 2 +swap -background none -layers merge +repage \) \
-delete 1,2 -gravity center -compose over -composite sky_ball4.jpg


Otherwise, something is wrong with your version of IM -- possibly too old and has a bug?
Post Reply