Combining images in ImageMagick with drop shadow - image

I am cropping and blurring a 960x960px image to 960x416 using GraphicsMagick:
gm convert -resize 960x416^ -gravity center -crop 960x416+0+0 +repage in.jpg bg.png
gm mogrify -gaussian 25x10 bg.png
After that, I create a 200x200px thumbnail of same initial image:
gm convert -resize 200x200 in.jpg top.png
On the last step, I combine both images, where the thumbnail will be placed on the top left position of the background image:
gm composite top.png bg.png -geometry 960x416+50+16 out.jpg
This works like a charm. But what I now need is a automatically generated dropshadow for the image top.png when it will be composited on the top of the bg.png in the last step. Is this possible?

Related

Cutting out a mask from a image with ImageMagick

I'm trying to cut out a shape from an image based on a mask I have. I tried a number of ways but I'm really struggling to get the result I need.
I'm using ImageMagick 7.1.0-51 Q16-HDRI on Windows.
The "base" image:
https://imgur.com/a/j1kioWu
The mask i'm using:
https://imgur.com/a/OcArICa
Expected result(photoshoped):
https://imgur.com/a/GjRoxyS
Edit: Reuploaded direct on imgur to maintain transparent background
In Imagemagick, you want to invert (negate) the polarity of black and white, then do a -compose difference -composite, then invert again.
Hair:
Face:
magick hair.png face.png -alpha off -colorspace gray -negate -compose difference -composite -negate result.png
Result:
If you want pure white in the face area, threshold the two images after the conversion to grayscale
magick hair.png face.png -alpha off -colorspace gray -auto-threshold otsu -negate -compose difference -composite -negate result2.png
Result 2:
ADDITION
If your input images have transparent backgrounds, then you have to extract the alpha channels, combine them to do the difference and then put that alpha channel back on the input.
Unix Syntax:
magick hair.webp \
\( +clone face_mask.webp -alpha extract -compose difference -composite \) \
-alpha off -compose copy_opacity -composite result.png
For Windows,remove the \ in front of the parentheses and change the end of line \ to ^.

Imagemagick fill with opaque color Gray issue

I need create 50% RGB Gray canvas from existing image to my task.
And using this command to do this:
magick.exe 00_B.tif -fill fractal -opaque fractal 000.png
or
magick.exe 00_B.tif -alpha Opaque +level-colors "rgb(50%,50%,50%)" 000.tif
Original image is 16bit RGB
But Imagemagick always save png or tif or jpg as Grayscale image.
When i define non Gray color
magick.exe 00_B.tif -fill fractal -opaque Sienna 000.tif
ImageMagick save RGB image with Sienna color on it.
What i missed and how should i create 50% Grayscale image?
I plan to use it with -write MPR:GrayLayer in final command so not actual write as a RGB file is needed.
In ImageMagick, you can create a 50% Gray image and save as RGB as follows:
For TIF output:
convert 00_B.tif -fill "gray(50%)" -colorize 100 -type truecolor result.tif
For PNG output:
convert 00_B.tif -fill "gray(50%)" -colorize 100 PNG24:result.png
Alternately:
convert 00_B.tif -evaluate set 50% -type truecolor result.tif
convert 00_B.tif -evaluate set 50% PNG24:result.png

How I can remove background color from image using GraphicsMagick?

How I can remove background color from image using GraphicsMagick? I need to delete rgb(255,255,255) and rgb(254,254,254) colors from image and replace them to transparency.
Thank you.
you should tinker with fuzz -parameter to match #fefefe
gm convert in.png -fuzz 3% -transparent "#ffffff" out.png
Should comment but cannot.
gm convert -geometry 50x50! -background white -extent 0x0 +matte in.png out.jpg or
gm convert -background color -extent 0x0 +matte src.png dst.png

Imagemagick gradient from left and right

I want to use Imagemagick to add a transparent gradient from the left and right to be composed with an image.
I can generate the image with:
convert -size 100x100 gradient: -function Polynomial -4,4,0 -distort SRT 90 gradient.png
And it looks like:
I can also compose that image on top of the image I want with:
composite original.jpg -compose Multiply gradient.png final_image.jpg
All of this works fine. My question is, how do I change the color of that gradient?
Thanks!
Simply add comma-separated colors after gradient: option:
convert -size 100x100 gradient:white,blue -function Polynomial -4,4,0 -distort SRT 90 gradient.png
Note, that -function converts channels too, so colors in gradient wont be original.
Found a way around this by doing
convert input.jpg -alpha set -virtual-pixel transparent -background red -channel A -blur 0x34 -level 75%,100% +channel -flatten final.jpg
which works in my case, giving me:

Combine commands in ImageMagick

I want to generate image with ImageMagick by this algorithm:
get image img.png
add mask to it with mask.png
put result to another image bg.png
create result image result.png
I wrote it, but I cant send first result to second command. Can you help me?
It's working:
composite -compose CopyOpacity mask.png img.png masked.png
composite -geometry +5+5 masked.png bg.png result.png
It's not working:
composite -compose CopyOpacity mask.png img.png -geometry +5+5 bg.png
result.png
type in your console, with all files in the same directory and being in the same directory:
composite -compose CopyOpacity mask.png img.png masked.png && composite -geometry +5+5 masked.png bg.png result.png

Resources