image-magic: select orientation of the stacked image - imagemagick

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

Related

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...

Treasure hunt for edges

I want to make a children's treasure hunt where the next location is given by a picture e.g.
To make a more suitable printable picture, I can use -canny like this:
convert hut.jpg -canny 0x1+10%+30% -negate hutCanny.jpg
To make it more interesting, I was thinking that I want to make two images -one with horizontal lines and one with vertical lines:
convert hut.jpg -colorspace gray -morphology Convolve Sobel -negate hutH.jpg
convert hut.jpg -colorspace gray -morphology Convolve Sobel:90 -negate hutV.jpg
I would like the location to be only guessable when both picture are found and can be combined using a light source. The problem is that Sobel not only detects vertical lines but also angled lines. As can be seen, the location is far too easy to recognise with just one picture. I have been trying with different kernels and trying to erode the pictures. -nothing woks.
How do I make two images that by themselves are not 'guessable' but can be combined to one. e.g. by making one image with only near horizontal lines and an other with only near vertical lines?
You could do something like the following in ImageMagick. Make a random mask and apply it to the image. Then invert the mask and do the same. The two images, when added together, will make the input.
Input:
convert \( hut.png -write mpr:img +delete \) \
\( mpr:img +noise random -channel g -separate +channel -blur 0x5 -threshold 50% +write mpr:mask +delete \) \
\( mpr:img mpr:mask -compose multiply -composite +write hut_out1.png \) \
\( mpr:img \( mpr:mask -negate \) -compose multiply -composite +write hut_out2.png \) \
null:
Output 1:
Output 2:
ADDITION
If it has to be grayscale, then you can do the above and make each output gray.
convert \( hut.png -write mpr:img +delete \) \
\( mpr:img +noise random -channel g -separate +channel -blur 0x5 -threshold 50% +write mpr:mask +delete \) \
\( mpr:img mpr:mask -compose multiply -composite -colorspace gray +write hut_out1.png \) \
\( mpr:img \( mpr:mask -negate \) -compose multiply -composite -colorspace gray +write hut_out2.png \) \
null:
Output 1:
Output 2:
Now add them together to reconstitute:
convert hut_out1.png hut_out2.png -evaluate-sequence add hut_out12.png

ImageMagick Border

I'm trying to apply the Torn Paper Edge to a GIF I created. How can I do so?
Website: https://legacy.imagemagick.org/Usage/thumbnails/#torn
Input:
Linux or Mac Syntax:
convert thumbnail.gif \( +clone -alpha extract -virtual-pixel black -spread 10 -blur 0x3 -threshold 50% -spread 1 -blur 0x.7 \) -alpha off -compose Copy_Opacity -composite torn_paper.png
Windows Syntax:
convert thumbnail.gif ( +clone -alpha extract -virtual-pixel black -spread 10 -blur 0x3 -threshold 50% -spread 1 -blur 0x.7 ) -alpha off -compose Copy_Opacity -composite torn_paper.png
See https://legacy.imagemagick.org/Usage/thumbnails/#torn
Note: For ImageMagick 7, replace convert with magick.

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

Create drop shadow effects in 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

Resources