Page 1 of 1
Creating an image corner relative to the size of the picture
Posted: 2012-07-09T12:19:55-07:00
by louim
Greetings everyone.
I've been trying since the past few day to generate an image corner looking like this:
where the red corner is generated over the image and the white space is actually transparent, so I can put the image on any kind of background and it'll show trough.
The problem I have is that I need to generate multiple picture like this one, except they have different sizes. I am wondering how is it possible to generate this corner relative to the image size?
I'm able to generate the square gradient (tested at 100x100) but I have no idea how to create it relative to the picture size, and create & apply the cropping mask so they fit.
Any help will be gladly appreciated.
Re: Creating an image corner relative to the size of the pic
Posted: 2012-07-09T13:36:30-07:00
by fmw42
Are you asking how to apply the same size fold to any image or do you need to have the size of the fold be bigger for larger images and smaller for smaller images. If the latter, then please clarify how big it should be in percent of the width or the height (as they could be different).
If you are on unix or windows w/cygwin, see my scripts, pagepeel and pagecurl, at the link below.
Re: Creating an image corner relative to the size of the pic
Posted: 2012-07-09T15:03:30-07:00
by fmw42
This should work for unix to make a 20% sized corner.
infile="logo:"
pct=20
lw=`convert $infile -format "%[fx:w-1]" info:`
lh=`convert $infile -format "%[fx:h-1]" info:`
size=`convert $infile -format "%[fx:$pct*min(w,h)/100]" info:`
convert $infile \
\( -size ${size}x${size} xc: -sparse-color barycentric '0,0 red -%w,%h red %w,%h black' +repage \) \
\( -size ${size}x${size} xc: -set colorspace RGB -sparse-color barycentric '0,0 white -%w,%h white %w,%h black' -threshold 50% +repage \) \
\( -clone 1 -clone 2 -compose multiply -composite \) \
-delete 1,2 -gravity southeast -compose over -composite \
-fill none -draw "matte $lw,$lh floodfill" logo_redcorner.png
see
http://www.imagemagick.org/Usage/canvas ... _gradients
http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/draw/#matte
Re: Creating an image corner relative to the size of the pic
Posted: 2012-07-09T19:57:56-07:00
by anthony
The barycentric method use to generate the gradient ensures that the gradient falling bteeen thw top-left to bottom-right diagonal, is at a 50% level between the top-right and bottom-left.
But if the image is square, then a baricentric with just two points will do the job (IM will calculate the third point)
-sparse-color barycentric '0,0 white %w,%h black'
Just a matter of coloring and setting transparency in that image.
As the overlay is square with transparency, just overlay it using 'Copy' Compostion.
That replaces just the overlay area with both color and transparency.
http://www.imagemagick.org/Usage/compose/#copy
This compose method is not often used, but in this case it is ideal.
Re: Creating an image corner relative to the size of the pic
Posted: 2012-07-09T21:30:12-07:00
by fmw42
anthony wrote:The barycentric method use to generate the gradient ensures that the gradient falling bteeen thw top-left to bottom-right diagonal, is at a 50% level between the top-right and bottom-left.
But if the image is square, then a baricentric with just two points will do the job (IM will calculate the third point)
-sparse-color barycentric '0,0 white %w,%h black'
Just a matter of coloring and setting transparency in that image.
As the overlay is square with transparency, just overlay it using 'Copy' Compostion.
That replaces just the overlay area with both color and transparency.
http://www.imagemagick.org/Usage/compose/#copy
This compose method is not often used, but in this case it is ideal.
Thanks Anthony. I knew there was compose method to do that, but could not think of it.
Here is the revised script according to Anthony's suggestions, which avoids the matte floodfill -draw:
infile="logo:"
pct=20
size=`convert $infile -format "%[fx:$pct*min(w,h)/100]" info:`
convert $infile \
\( -size ${size}x${size} xc: -sparse-color barycentric '0,0 red %w,%h black' +repage \) \
\( -size ${size}x${size} xc: -set colorspace RGB -sparse-color barycentric '0,0 white %w,%h black' \
-threshold 50% +repage \) \
\( -clone 1 -clone 2 -alpha off -compose copy_opacity -composite \) \
-delete 1,2 -gravity southeast -alpha set -compose copy -composite \
logo_redcorner.png
Re: Creating an image corner relative to the size of the pic
Posted: 2012-07-10T10:42:40-07:00
by louim
Many thanks!!!
It is exactly what I needed. I'm really impressed by the image magick community. Quick and efficient answers!
Cheers!
Re: Creating an image corner relative to the size of the pic
Posted: 2012-07-10T18:50:11-07:00
by anthony
fmw42 wrote:Thanks Anthony. I knew there was compose method to do that, but could not think of it.
try this... Uses a large fuzz to set transparency

You can now overlay that directly using just one 'Copy' compose.
Code: Select all
convert -size 256x256 xc: -set colorspace RGB \
-sparse-color barycentric '0,0 white %w,%h black' \
-fuzz 50% -transparent black \
+level-colors black,red show: