Problem with compsiting images

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?".
Post Reply
Kira
Posts: 2
Joined: 2011-06-07T08:06:21-07:00
Authentication code: 8675308

Problem with compsiting images

Post by Kira »

Hi,

I'd like to add a blurred border arround an image and add a watermark in the lower right corner.

My approach was:

Code: Select all

convert \( \
	input.jpg \
	\( +clone -blur 10x4 -fill black -colorize 25% \) \
	\( +clone -gamma 0 -shave 40x40 -bordercolor white -border 40x40 \) -composite \
	\( +clone -gamma 0 -shave 40x40 -bordercolor lightgray -border 1x1 -bordercolor black -border 39x39 \) -compose screen -composite \
	\) \
	overlay.png -gravity SouthEast -compose copy -composite \
	output.jpg
but for some reason the watermark (overlay.png) is only visible in the 40x40 border.. it's cut off by the center of the image.

Does anyone know what the problem may be?

And, another problem.. I'd like the 1px border between the blurred border and the normal central image to be transparent.. I thought if I use screen as compose method and set the bordercolor to lightgray this would work.. but it didn't.

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

Re: Problem with compsiting images

Post by fmw42 »

Do you want the blur inside the bounds of the input image or outside so that the image is bigger?

For the latter see my script, imageborder, at the link below.


Do you want the watermark image to cover the blurred area or be inside of that?

-gamma 0 is going to result in pure black, is that what you are trying to do?

I suggest you put -write tmpX.png statements in various places where X=0,1,2,3... to get temporary images to see where things are going wrong.


try this:

Image
Image

convert zelda1.jpg cyclops.jpg \
\( -clone 0 -blur 0x4 -write tmp1.png \) \
\( -clone 0 -shave 41x41 -bordercolor white -border 1 -write tmp2.png \) \
\( -clone 2 -clone 3 -gravity center -compose over -composite -write tmp3.png \) \
\( -clone 4 -clone 1 -gravity southeast -geometry +40+40 -compose blend -define compose:args=50,50 -composite \) \
-delete 0-4 zelda_cyclops.jpg


Image

I left in the -write statements to show you the steps. You can remove them.

see
http://www.imagemagick.org/script/compose.php
http://www.imagemagick.org/Usage/compose/#watermark
Kira
Posts: 2
Joined: 2011-06-07T08:06:21-07:00
Authentication code: 8675308

Re: Problem with compsiting images

Post by Kira »

Hi,

thanks a lot it's working very nice - only two problems left:

1) I'd like the white border-line to be a bit transparent, is this possible?

2) The Blur takes a veerryy looong time at large images.. and since I only need to blur the outer 40pixels, is there any way to improve the speed by not blurring the whole image?

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

Re: Problem with compsiting images

Post by fmw42 »

Kira wrote:Hi,

thanks a lot it's working very nice - only two problems left:

1) I'd like the white border-line to be a bit transparent, is this possible?

2) The Blur takes a veerryy looong time at large images.. and since I only need to blur the outer 40pixels, is there any way to improve the speed by not blurring the whole image?

Thanks,
Kira

1) specify a partially transparent color for the border such as "gray(100%,0.5)" for 50 % transparent white. (be sure to use quotes). see http://www.imagemagick.org/script/color.php

2) I am not sure, unless you use a mask to define the area you want to blur. I have never used that before so don't know. But see -clip-mask at http://www.imagemagick.org/script/comma ... #clip-mask

Anthony might be better able to answer your second question.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Problem with compsiting images

Post by anthony »

Believe it or not one of the faster ways to do large blurs is to resize the image smaller doing pixel averaging and larger using a -filter gaussian.

For example

Code: Select all

  convert logo: -filter gaussian -resize 2% -resize 5000%  show:
However at blurs smaller than this it does tend for become a little squarish. That is resize blurs work better for very large blurs.

Alternative you can use -distort Resize which is a slower but produces less squareish results

Code: Select all

   convert logo: -filter gaussian -distort resize 10% -distort resize 1000%  show:
Another method is you do multiple smaller blurs. Which are generally faster than one massive blur.

and finally you can limit the radius of the blur to say 3 times the sigma value, which is typically good enough.

By default IM will work out a radius that has an rounding error less than the quantum level. as such the radius of a blur on a Q8 is far smaller than a radius for a blur on a Q16. This may be far too big, and can be the cause of the slow down.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply