imagemagick: -gravity SouthEast -geometry offset did not work - macos

when replacing part of an image,
from
to
I replaced two parts of the image.
My solution is
with convert 1.png \( 1.png -crop 200x200+300+800 +repage \) -gravity SouthWest -geometry +0+0 -compose Copy -composite 2.png,
I got
with convert 2.png \( 2.png -crop 350x450+1252+200 +repage \) -gravity SouthEast -geometry -350-450 -compose Copy -composite 4.png
I got the same image, what is wrong with me?
with convert 2.png \( 2.png -crop 350x450+1252+200 +repage \) -gravity Center -geometry +626+349 -compose Copy -composite 3.png, got it .
not very familiar with the mechanism

Using ImageMagick, in place of:
convert 2.png ( 2.png -crop 350x450+1252+200 +repage ) -gravity
SouthEast -geometry 0X0-350-450 -compose Copy -composite 4.png
Use:
convert 2.png \( +clone -crop 350x450+1252+200 +repage \) -gravity SouthEast -geometry -350-450 -compose over -composite 4.png
Or:
convert 2.png \( +clone -crop 350x450+1252+200 +repage \) -gravity center -geometry -350-450 -compose Copy -composite 4.png
That should make a difference. Do not add WxH (0x0) to your -geometry as that may try to make a W=0 and H=0 image, which will either fail or not show. See https://imagemagick.org/Usage/layers/#convert
The +clone, just copies the previous image in the command line, which is 2.png. Repeating 2.png is OK, but will be slower as it has to read the 2.png image a second time.
Note, it is best not use images to show code. Just paste the code into the form and use the {} button to make it show in gray background.

convert 2.png \( +clone -crop 350x450+1252+200 +repage \) -gravity SouthEast -geometry +0+0 -compose over -composite 99.png
experimented and figured out

Related

How to add a background to a transparent PNG file?

I'm trying to add a PNG file as background to an PNG image with transparent regions using ImageMagick like so:
convert input.png -texture bg.png output.png
I'm not so far to find out how to fill my background to 100% width / height, because the above example does not work. I end up with the same file that is transparent and I don't know why.
How can I apply a background that uses full width/height across the whole file? (Preferable using the cover method, meaning to keep aspect ratio of the background and cutting overlaps)
If you want to tile out the background then on Unix, try
convert input.png \( +clone -tile bg.png -draw "color 0,0 reset" \) +swap -compose over -composite output.png
On Windows:
convert input.png ( +clone -tile bg.png -draw "color 0,0 reset" ) +swap -compose over -composite output.png
If you just want to resize the background, then on Unix try
dims=$( convert input.png -format "%wx%h" info: )
convert input.png \( bg.png -resize $dims +repage \) +swap -compose over -composite output.png
I do not know Windows that well to tell you how to do the variable
On ImageMagick 7, in Unix, you can do it easier as:
magick input.png -set option:dims "%wx%h" \( bg.png -resize "%[dims]" \) +swap -compose over -composite output.png
Or in Windows:
magick input.png -set option:dims "%wx%h" ( bg.png -resize "%[dims]" ) +swap -compose over -composite output.png

Reduce size of an image when it is fusioned with other using ImageMagick from terminal in Linux

I am having these two pictures, labeled 1.png and 2.png, respectively:
When I run this code from ImageMagick in my Linux terminal:
composite -blend 75 -gravity West 2.png 1.png prueba.png
I get this result:
However, I would like the logo (2.png) to be half or one-third size reduced and placed in the bottom left corner. How can I do it from the terminal?
You can do that in ImageMagick by using the convert syntax. It is more flexible than the composite syntax.
convert 1.png \( 2.png -resize 50% \) -gravity southwest -define compose:args=75 -compose blend -composite 1_2.png
If you want to move it further left, you can simply chop off some of the left side before compositing using ImageMagick.
convert 1.png \( 2.png -resize 50% -gravity west -chop 20x0 \) -gravity southwest -define compose:args=75 -compose blend -composite 1_2_b.png
Alternately, you can simply trim the excess empty space around the 2.png before blending.
convert 1.png \( 2.png -resize 50% -trim +repage \) -gravity southwest -define compose:args=75 -compose blend -composite 1_2_c.png

Image circle cropping in imagemagick

People, I am using imagemagick to crop a circle out of an image. But I am getting nothing when I run this command :
convert input.jpg +clone -threshold -1 -negate -fill white -draw "circle 539,539 539,0" -alpha off -compose copy_opacity -composite output_circ.jpg
I am getting an output like this:
Please let me know if I am missing something.
Fundamentally, you are only missing one aspect - JPEG files cannot store transparency, so you need to use a PNG or GIF, for example.
convert input.jpg -alpha on \( +clone -threshold -1 -negate -fill white -draw "circle 539,539 539,0" \) -compose copy_opacity -composite output_circ.png

Can you help me get rid of an intermediary output in my imagemagick convert commands?

I have the following convert command in bash.
convert "$WALLPAPER1" -resize "${H[0]}"x"${V[0]}"^ -gravity center -crop "${H[0]}"x"${V[0]}"+0+0 "$WALLPAPERS/.temp1.jpg"
convert "$WALLPAPER2" -resize "${H[1]}"x"${V[1]}"^ -gravity center -crop "${H[1]}"x"${V[1]}"+0+0 jpg:- |
convert "$WALLPAPERS/.temp1.jpg" - +append "$WALLPAPERS/.temp.jpg"
Is there a way I can get rid of the "$WALLPAPERS/.temp1.jpg" intermediary? So is there a way to carry over the output of the first convert over to the input of the third convert?
convert "$WALLPAPER1" -resize "${H[0]}"x"${V[0]}"^ -gravity center -crop "${H[0]}"x"${V[0]}"+0+0 -write mpr:temp1 +delete \
"$WALLPAPER2" -resize "${H[1]}"x"${V[1]}"^ -gravity center -crop "${H[1]}"x"${V[1]}"+0+0 -write mpr:temp2 +delete \
-gravity north mpr:temp1 mpr:temp2 +append "$WALLPAPERS/.temp.jpg"
There was no need to have 3 convert calls. Instead of writing to file you can write to memory-program-register (mpr) and then recall later. The +delete deletes the original image.

How do I efficiently concatenate ImageMagick and convert commands to produce a no of images

I have a big big size image of dimensions 4000*4000. I want to carry out various operations on the image :
convert a.jpg -crop 6x6# +repage +adjoin tile_6_%d.jpg
convert a.jpg -crop 9x9# +repage +adjoin tile_9_%d.jpg
convert a.jpg -crop 3x3# +repage +adjoin tile_3_%d.jpg
convert a.jpg -resize 120x120 thumbnail.jpg
Thus creating a batch of 36+81+9+1 = 127
I am trying to do something like
convert a.jpg \
\( +clone -resize 66% -crop 6x6# +repage +adjoin -write tile_6x6_%d.jpg +delete \) \
\( +clone -resize 33% -crop 3x3# +repage +adjoin -write tile_3x3_%d.jpg +delete \) \
\( +clone -crop 9x9# +repage +adjoin -write tile_9x9_%d.jpg +delete \) \
-density 150 -quality 50 -resize 120x120 thumbnail.jpg
But this doesn't work the desired way and produces some 250 files. what is wrong here ? What is the best way to concatenate all these commands ?
+delete deletes only the last image in the image sequence. You want -delete 0--1, which means delete images 0 through -1, where the negatively indexed -1 refers to the last image in the sequence.
To elaborate just a bit, each of those -crop commands creates several images, so you want to make sure that you delete all of them from the stack after writing them to disk. When working with a complex convert command line like this, a good way to see what is going on with your image stack(s) at any point is to insert a -write info:.

Resources