ImageMagick and Piping - bash

I have the following commands that create a sprite containing a normal state and a hover state:
convert -background none -pointsize 11 -fill white -size 100x -gravity NorthWest caption:'Test' top.png
convert -background none -pointsize 11 -fill grey -size 100x -gravity SouthWest caption:'Test' bottom.png
montage top.png bottom.png -geometry +0+0 -tile 1x2 -background none test.png
I'm creating two images, top.png and bottom.png then combining them to create test.png.
Is there a way to do this without having to write the top and bottom images to disc?
Can I pipe the commands together some how?
Update: Solution
montage \
<(convert -background none -pointsize 11 -fill white -size 100x -gravity NorthWest caption:'Test' png:-) \
<(convert -background none -pointsize 11 -fill grey -size 100x -gravity SouthWest caption:'Test' png:-) \
-geometry +0+0 -tile 1x2 -background none test.png

This is completely untested, so make sure to backup the relevant images before testing:
montage \
<(convert -background none -pointsize 11 -fill white -size 100x -gravity NorthWest caption:'Test' png:-) \
<(convert -background none -pointsize 11 -fill grey -size 100x -gravity SouthWest caption:'Test' png:-) \
-geometry +0+0 -tile 1x2 -background none test.png
(This is called "Process Substitution")

Related

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

imagemagick: -gravity SouthEast -geometry offset did not work

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

ImageMagick: Why won't this text expand to fill?

I'm reading the text handling docs for label and it seems if I specify -size it should magically get as big as possible to fill the space.
I want to make it so this text gets as big as possible. I will set the \n characters myself in the title (if absolutely necessary).
I'd rather the \n get calculated automatically, but it seems label is what makes it the biggest possible (but doesn't support automatic \n), while caption will add \n where appropriate (but doesn't support a dynamic size which fills to fit a space).
My goal is to basically get the BIGGEST possible text, whether it's on 1 line or 3, to fit in the green box (between the 2 red ****** lines).
Below are 2 examples of how it won't change. The green color is just temporary so I can debug.
Heres my code for this text piece (without all the rest):
-size 290x54 -background green -fill blue -font ArialB -gravity center label:'Join Us'
Multiline...
-size 290x54 -background green -fill blue -font ArialB -gravity center label:'Join Us Tomorrow\nFor An HVAC Meeting'
I don't know if this is possible, but ideally it should ask "if the title is on 1 line, what is the max size it could be? if I put a \n after word 1, what is the max size it could be? if i put a \n after word 2, what is the max size it could be?"... and then choosing the largest of those.
Your command works for me with one correction. Apparently, the pointsize leaks from the your main command into the parenthesis processing, even though I added -respect-parenthesis. So the solution is to add +pointsize into the parenthesis command. Here is my command and result.
magick -respect-parenthesis -size 298x248 canvas:white \( 'arrows.png' -resize 300x \) -gravity northwest -geometry +0+140 -compose over -composite -bordercolor '#cccccc' -border 1 -font Arial -fill red -pointsize 22 -gravity north -annotate +0+4 '*************************' -font Arial -fill red -pointsize 22 -gravity north -annotate +0+68 '*************************' -font Arial -fill green -pointsize 15 -gravity south -annotate +0+64 'hvac.com' \( -size 279x55 +pointsize -background green -fill blue -font ArialB -gravity center caption:'test headline' \) -gravity center -geometry +0-82 -compose over -composite output.png
Note that I put the arrows.png file where I could access it at the same level as where the command is being issued. You can change the path to it.
In ImageMagick use caption by specifying both the widthxheight but not the pointsize. ImageMagick will figure out the proper pointsize to fill the text to the box. For example:
convert -size 500x200 -background white -font arial -fill black -gravity center caption:"Testing" -bordercolor red -border 1 test1.png
convert -size 500x200 -background white -font arial -fill black -gravity center caption:"Should Be Bigger" -bordercolor red -border 1 test2.png
convert -size 500x200 -background white -font arial -fill black -gravity center caption:"This is a title that will be fairly long and I want it to fit nicely" -bordercolor red -border 1 test3.png
You can also include the pointsize, so long as your text is not too long for the area of the box.
convert -size 500x200 -background white -font arial -fill black -pointsize 48 -gravity center caption:"Testing" -bordercolor red -border 1 test1b.png
convert -size 500x200 -background white -font arial -fill black -pointsize 48 -gravity center caption:"Should Be Bigger" -bordercolor red -border 1 test2b.png
convert -size 500x200 -background white -font arial -fill black -pointsize 48 -gravity center caption:"This is a title that will be fairly long and I want it to fit nicely" -bordercolor red -border 1 test3b.png
However, if you choose a font that is too big, you will get this:
convert -size 500x200 -background white -font arial -fill black -pointsize 64 -gravity center caption:"This is a title that will be fairly long and I want it to fit nicely" -bordercolor red -border 1 test3c.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

Imagemagick text with transparent background

I want to create an iamge with image magick that creates me a text with a transparent background.
So far I used this code but it creates me a black background.
convert -debug annotate -size 720x480 -background none xc:black -fill white -stroke white -font Arial -pointsize 16 90x25 -draw "text 120,370 'move'"-font Arial -pointsize 16 50x25 -draw "text 250,370 'text'"-font Arial -pointsize 16 105x25 -draw "text 360,370 'images'"-font Arial -pointsize 16 115x25 -draw "text 500,370 'another text'" TextTransp.png
The file shall be a .png.
There should basically be a a white text with a transparent background.
I think you need xc:none rather than xc:black, like this:
convert -size 720x480 xc:none -draw "text 200,50 'Hello there'" result.png
(I added a red border just so you can see the extent of it.)
I know it's a late answer, but you should use something like this:
convert -size 115x25 xc:none -font PATH\TO\YOUR\FONT -pointsize 16 -annotate +0+0 "TEXT" PATH\TO\FINAL\FILE.png
You can also add:
-gravity Center if you want your text to be centered
-fill rgba(100%%,0,0,0.80) if you want your text to be semitransparent
More on creating different canvases here.

Resources