Create drop shadow effects in Imagemagick - imagemagick

The border shadow effects used in the images of this blog post seem to be embeded in the images themselves (not css3). How can it be created in imagemagick?
Edit 1:
The solution which I found quite accidentlly is posted below as an answer.

Somehow I found the command which does what I wanted exactly:
For images which are already scaled and compressed:
convert input.jpeg -bordercolor white -border 13 \( +clone -background black -shadow 80x3+2+2 \) +swap -background white -layers merge +repage output.jpg
For creating thumbnails:
convert input.jpeg -thumbnail 200x200 -bordercolor white -border 6 \( +clone -background black -shadow 80x3+2+2 \) +swap -background white -layers merge +repage output.jpg
For raw images:
convert input.jpeg -scale 600x400 -quality 86 -strip -bordercolor white -border 13 \( +clone -background black -shadow 80x3+2+2 \) +swap -background white -layers merge +repage output.jpg

There is a -shadow argument on convert that has options to do this.
http://web.archive.org/web/20120607055659/http://blog.bemoko.com/2009/07/01/add-shadow-and-border-to-images-with-imagemagick/

Shutter uses the following command https://github.com/shutter-project/shutter/blob/master/share/shutter/resources/system/plugins/perl/spshadow/spshadow#L375
convert in.png -gravity 'northwest' -background 'rgba(255,255,255,0)' -splice '10x10' \( +clone -background '#005f005f005f0000' -shadow "80x3-1-1" \) +swap -background none -mosaic +repage \( +clone -background '#005f005f005f0000' -shadow "80x3+5+5" \) +swap -background none -mosaic +repage out.png

Related

image-magic: select orientation of the stacked image

I am using montage of imagemagic to stack horizontally 3 types of image producing Nx3 table:
montage \( "${output}/type1*.png" \) \( "${output}/type2*.png" \) \( "${output}/type3*.png" \) -geometry 800x600+1+1 -frame 4 -background white -mattecolor lightgoldenrod2 -mode Frame -bordercolor white ${output}/summary.png
is it possible to add here some option in order to produce vertically-stacked table of the Nx3 elements. I found only a possibility to do it via
convert where I need to specify -apend option:
convert \( "${output}/type1*.png" -bordercolor lightgoldenrod2 -border 0x2 -append \) \( "${output}/type2*.png" -bordercolor lightgoldenrod2 -border 0x2 -append \) \( "${output}/type3*.png" -bordercolor lightgoldenrod2 -border 0x2 -append \) -bordercolor lightgoldenrod2 -border 2x0 +append -background white -alpha deactivate ${output}/summary.png
You can do that in Imagemagick by transposing all your images, do the montage, then transpose the result using pipes between convert and montage and convert.
convert lena.jpg mandril3.jpg zelda1.jpg redhat.jpg -transpose miff:- | montage - -tile 2x2 miff:- | convert - -transpose result.png

How to colorize an image with multiply to add transparency to the colour with Image Magick

I would like to colorize an image with two colours, red on the left half and green on the right half but the colorize function just adds a coloured overlay to the image rather than multiplying it on. So I would like my image to look like this but it is currently looking like this. Here is the original image
My code at the moment is this:
convert normal.png \
\( -clone 0 -crop 50x100% -fill red -colorize 60% \) \
\( -clone 0 -crop 50x100%+64 -fill green -colorize 60% \) \
-delete 0 -background none -flatten result.png
I have tried adding -compose multiply -composite to the code but I just get this which has the right effect but I cannot get it to the position that I want, heres the code for that:
convert normal.png \
\( -clone 0 -crop 50x100% -fill red -colorize 70% \) \
\( -clone 0 -crop 50x100%+64 -fill green -colorize 70% \) \
-background none -compose multiply -composite result.png
One simple approach would be to assemble the red-green overlay inside parentheses, then do a multiply composite over the input image.
magick lena_circ.png -size %wx%h \
\( xc:red xc:green +append -scale 50x100% \) \
-compose multiply -channel rgb -composite result.png
That command give me this result...

imagemagick nested gravity centering

I am trying to composite two images with gravity, and then position them within a larger image at a geometry.
When I try
magick -size 1045x837 xc:blue \( -size 345x437 xc:red \( -size 275x417 xc:white -resize 345x437 -gravity center \) -composite \) -geometry +26+53 -composite test-y.png
I get
and when I do
magick -size 1045x837 xc:blue \( -size 345x437 xc:red \( -size 275x417 xc:white -resize 345x437 \) -composite \) -geometry +26+53 -composite test-x.png
I get
I think this involves clone and related, maybe similar to this answer, but I just can't find the combo.
What do I need to do, to get the white centered within the red, and geometrically placed in the upper-left corner?
It's not clear exactly what you want, but I think you are falling foul of the fact that -gravity is a "setting". As such, it remains set until changed, so you probably want this, where I reset the gravity to NorthWest before the final composite:
magick -size 1045x837 xc:blue \( -size 345x437 xc:red \( -size 275x417 xc:white -resize 345x437 -gravity center \) -composite \) -gravity northwest -geometry +26+53 -composite result.png
You might find -extent a simpler way to fill out the white to a given size using a red background:
magick -size 1045x837 xc:blue \( -size 275x417 xc:white -resize 345x437 -background red -gravity center -extent 345x437 \) -gravity northwest -geometry +26+53 -composite result.png

ImageMagick draw rectangle with special corners

Hi I would like to create a mask image with "special corners" I am calling them special because I don't really know how to call them in english here is what I would like to achieve:
what I am using now is
convert xc:black -size 300x300 -fill white -draw "roundrectangle 3,3,296,296,5,5"
but this gives me rounded corners. Thank you in advance for any suggestions.
Here's one way of doing it.
convert -size 300x300 xc:none \
-shave 10 -bordercolor black -border 10 \
-fill black -draw "polyline 0,0 30,0 0,30" \
\( +clone -flip \) -gravity north -composite \
\( +clone -flop \) -gravity south -composite -background white -flatten result.png
That says... "Draw a rectangle your full size and transparent, shave 10 pixels off all round and add a 10 pixel black border (easier than doing the maths and making a 280x280 and adding 10 on each side). Draw a triangle in the top-left. Copy the whole shape and flip it and draw it on top of the original. Copy the whole shape and flop it and draw it again on the original. Now make all the transparent areas white."
Here is another way - maybe a little easier. Draw the original square, then copy it, enlarge it by square-root(2) (i.e. 141%), thicken the borders, rotate 45 degrees and composite it onto itself. Kinda depends how your brain works!
magick -size 300x300 xc:none -shave 10 -bordercolor black -border 10 \
\( +clone -scale 142% -shave 30 -border 30 -rotate 45 \) \
-gravity center -composite -background white -flatten result.png
Here is a link to a page showing how to do what you want along with other effects https://www.imagemagick.org/Usage/thumbnails/#rounded
This is the code from the page:
convert thumbnail.gif -alpha set -compose DstOut \
\( -size 20x15 xc:none -draw "polygon 0,0 0,14 19,0" \
-write mpr:triangle +delete \) \
\( mpr:triangle \) -gravity northwest -composite \
\( mpr:triangle -flip \) -gravity southwest -composite \
\( mpr:triangle -flop \) -gravity northeast -composite \
\( mpr:triangle -rotate 180 \) -gravity southeast -composite \
corner_cutoff.png
You should check out the examples as there is another method you could use for smaller images.

Setting opacity of each image drawn on canvas with imagemagick

I have the command below which takes multiple image sources and draw it onto 1 output.png file.
Convert img1.jpg -resize 1000x1000!
-draw "image over 169,555 875,109 'img1.png'"
-draw "image over 29,55 375,209 'img2.png'"
-draw "image over 129,525 15,29 'img3.png'"
png24:output.png
Is there a way to set the opacity of each of the images being drawn? where some might have opacity of 60% , while others have 100%
I tried this but doesn't work:
Convert img1.jpg -resize 1000x1000!
\( -alpha set -channel A -evaluate set 60% \) -draw "image over 169,555 875,109 'img1.png'"
\( -alpha set -channel A -evaluate set 100% \) -draw "image over 29,55 375,209 'img2.png'"
\( -alpha set -channel A -evaluate set 90% \) -draw "image over 129,525 15,29 'img3.png'"
png24:output.png
Thanks in advance
I think you want something like this...
convert img1.jpg -resize 1000x1000! \
\( img1.png -alpha set -channel A -evaluate set 60% -resize 707x447 \) -geometry +169+109 -composite \
\( img2.png -alpha set -channel A -evaluate set 100% -resize 347x155 \) -geometry +29+55 -composite \
\( img3.png -alpha set -channel A -evaluate set 90% -resize 115x497 \) -geometry +15+29 -composite \
png24:output.png

Resources