Imagemagick label issue - imagemagick

I am using imagemagick 6.2.8 and i want to add a label at the bottom of the image aligned on the right side.
this is my code:
convert image.png -gravity center -background "#f0f0f0" -font bgothm.ttf -pointsize 18 label:"text text" -append "append_image.png"
however the label is aligned to the left
How can i align the label to the right?
Edit:
I found this: Before IM v6.4.7 it was much more difficult to align appended images, and generally involved using a "-flop" for right alignment. Or using "-extent" or "-border" to adjust the image width for centered aligned appends.
But i never used imagemagick

To align bottom-right, use -gravity southeast.
convert image.png -gravity southeast -background "#f0f0f0" -font bgothm.ttf -pointsize 18 label:"text text" -append "append_image.png"

Edit: I have updated my solution to work with your ImageMagick version.
Do the double -flop trick. One flop to mirror the text, so it will be right aligned and one flop to mirror the append to make it readable:
convert image.png -background "#f0f0f0" -font bgothm.ttf \
-pointsize 18 label:"text text" -flop -append -flop "append_image.png"
Produces this image for me. Please note that the order of -flop -append -flop do matter!
But still, a better solution would be to upgrade ImageMagick to >= 6.4.7 and use -gravity SouthEast:
convert image.png -gravity SouthEast -background "#f0f0f0" -font bgothm.ttf \
-pointsize 18 label:"text text" -append "append_image.png"

Related

align text to left with imagemagick

I am using ImageMagick to add text to an image. I used to -gravity Center flag to put the text in the center of the image. But I think this is resulting in the text being center aligned too. I want the text at the center of the image but left aligned. Here is an example of what I'm trying to have:
This is the output I'm getting:
Current output
This is what I want:
This is my requirement
How do I accomplish this? This is my first time using ImageMagick. Please guide me.
Here is one way to do that in Imagemagick 6. I specify the background color, the font color (fill), the font and the pint-size and gravity west (left side). I use label: to create the two lines of text with a new line between them. This creates a text image of the size needed to hold the text. Then I pad the image all around that to the final size with the text image in its center using the same background color.
convert -background black -fill white -font ubuntu -pointsize 28 -gravity west label:"This is line 1 of text\nThis is line 2 of text" -gravity center -extent 400x300 result.png
See
https://imagemagick.org/Usage/text/
https://imagemagick.org/Usage/crop/#extent
ADDITION
If you want to put the text over an existing image, then you do something similar, but in place of the extent, we composite the text image over the background image.
The following is Unix syntax. For Window, remove the backslashes \ before the parentheses.
Input:
convert lena.png \( -background black -fill white -font ubuntu -pointsize 21 -gravity west label:"This is line 1 of text\nThis is line 2 of text" \) -gravity center -compose over -composite result.png
Result:
Or if you do not want the black background, use "none" for the color.
convert lena.png \( -background none -fill white -font ubuntu -pointsize 21 -gravity west label:"This is line 1 of text\nThis is line 2 of text" \) -gravity center -compose over -composite result2.png

Add top and left borders with magick command

Is there a way to add 5 or any number of white/transparent pixels at the top and left borders of an image with the magick command in Linux?
Use the -splice operator. First make a solid magenta rectangle:
magick -size 100x50 xc:magenta image.png
Now splice on a yellow chunk (so you can see it) 10 wide and 20 tall:
magick image.png -background yellow -gravity northwest -splice 10x20 result.png
Change yellow to none for transparent pixels.
Change magick to convert for v6 ImageMagick.
If you just want to splice to the East side:
magick image.png -background yellow -gravity east -splice 10x east.png
If you just want to splice to the South side:
magick image.png -background yellow -gravity south -splice x10 south.png

Use Imagemagick to create a bar with text at top of image and a different text bar at the bottom

Trying to create a solid 1920X1920 transparent canvas, then put a 1920X420 colored bar at the top with centered text and the same at the bottom with different centered text.
What I am doing now, when it gets created creates the 1920X1920 transparent image and puts the bar at the top with the text, but the bar at the bottom is non-existent.
convert -size 1920x1920 xc:"transparent" -size 1920x420 -font
Din-Condensed-Bold -pointsize 84 canvas:#800000 -fill black -
gravity center caption:"TEXT FOR THE BOTTOM" -gravity south
-composite -size 1920x420 -font Din-Condensed-Bold -pointsize 84
canvas:#800000 -fill black -gravity center caption:"TEXT FOR THE
TOP" -gravity north -composite newfile.png
A few things...
The main issue is that you set the background colour for a label with -background rather than canvas:.
Note that -font, -size, -pointsize and -fill are settings, as such they only need setting once and then they remain set until changed, so you don't need to keep repeating them.
Your command then becomes like this:
convert -size 1920x1920 xc:yellow \
-size 1920x420 -font "AppleChancery" -pointsize 84 -background "#800000" -fill black \
-gravity center caption:"TEXT FOR THE BOTTOM" -gravity south -composite \
-gravity center caption:"TEXT FOR THE TOP" -gravity north -composite result.png
Very Spanish, don't you think? :-)
In case you were actually looking for -undercolor:
convert -size 1920x1920 xc:yellow \
-size 1920x420 -font "AppleChancery" -pointsize 84 -background magenta -undercolor cyan -fill black \
-gravity center caption:"TEXT FOR THE BOTTOM" -gravity south -composite \
-gravity center caption:"TEXT FOR THE TOP" -gravity north -composite result.png
You say you want some "breathing space" around the edges, so I am adding a further example. I make the red and yellow boxes slightly smaller than the magenta background and position the top one inset 5 pixels from the top and 5 from the left using -geometry. Likewise, I set gravity to SouthWest and position the yellow box 2 pixels from the right edge and 25 from the bottom:
convert -size 100x100 xc:magenta -size 90x20 \
-gravity northwest xc:red -geometry +5+5 -composite \
-gravity southeast xc:yellow -geometry +2+25 -composite result.png

Overlap multiple images at some pixel level using Imagemagick

For example, I have 4 images with a size of 1000x800. I want to merge all these images into one image. I know there is a command of
convert +append image[1-4].jpg output.jpg
But I want to merge the second image into the first image by overlapping 250 pixels.
i.e., In my final image, image1 has 750 pixels as well as image2 & 3 and the last image has 1000 pixels.
By using above convert command, we will get an image size of 4000x800, but here I want it to be ((750*3)+1000*1)x800. i.e., 3250x800.
Also, how can I do this by appending vertically?
The "+smush" operator will act like "+append", but it takes an argument. A positive number will append the images separated by that many pixels. A negative number will append the images with that much overlap. Your example command would look like this...
convert image[1-4].jpg +smush -250 output.jpg
To append images vertically, use the "-smush" form of the operator. In either case the operator will align the images according to the current "-gravity" setting.
You do not say how you want to overlap them. If you do not need to blend, then in ImageMagick, you can use smush rather than append. Smush allows offsets (gaps) or overlaps. The former with positive values and the latter with negative values to overlap succeeding images. -smush appends vertically and +smush appends horizontally. The background color controls the spacing for gaps when using positive values for the argument.
So try
convert image[1-4].jpg +smush -256x0 output.jpg
or
convert image1.jpg image2.jpg image3.jpg image4.jpg +smush -256x0 output.jpg
or if those are the only images with that syntax, then
convert image*.jpg +smush -256x0 output.jpg
I just tested the following in Imagemagick 6.9.9.33 Q16 Mac OSX.
Note I tested using -smush with positive values so as to see gaps and not overlaps. That was just for testing. If you follow the last command, it should work fine with negative values, if you want to overlap rather than put gaps between the images.
Create 13 images named rose0.jpg ... rose12.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "0" test/rose0.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "1" test/rose1.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "2" test/rose2.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "3" test/rose3.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "4" test/rose4.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "5" test/rose5.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "6" test/rose6.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "7" test/rose7.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "8" test/rose8.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "9" test/rose9.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "10" test/rose10.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "11" test/rose11.jpg
convert rose: -fill white -gravity center -pointsize 18 -annotate +0+0 "12" test/rose12.jpg
Then smush them. This fails and only appends 0-2. (I think this stucture is limited to whatever digits it sees)
convert test/rose[0-12].jpg -smush 10 test/rose_smush.jpg
This works if using only one-digit numbers.
convert test/rose[0-9].jpg -smush 10 test/rose_smush.jpg
The proper way to do this is to use the following structure.
convert test/rose%d.jpg[0-12] -smush 10 test/rose_smush.jpg
See the section of Filename Reference at http://www.imagemagick.org/script/command-line-processing.php

How to -trim this image using ImageMagick?

I understand -trim can be used to remove extra whitespace.
How can Imagemagick be used to convert:
Note: The size of the bottom border to be removed is not known.
to
Note: the default -trim flag does not work.
The output of convert -trim pre-trim.png post-trim.png is:
which is missing the borders on the left and right.
Updated Answer
You can add some strips of colour down one side to protect the other 3 sides, then trim the side you want to trim and then remove the protective strips.
magick frame.png -gravity north \
-background cyan -splice x10 \
-background magenta -splice x10 \
-rotate 90 -trim +repage \
-gravity east -chop 10x -rotate -90 result.png
Here is the intermediate image of how it looks with the protective strips prior to trimming:
Kudos to Anthony Thyssen for his excellent ImageMagick Usage pages here.
Original Answer
You can chop 68 pixels off the bottom with:
convert frame.png -gravity south -chop x68 result.png

Resources