I am wondering how to add a shaded copyright text at the bottom of a jpeg. Currently I simply use:
convert input.jpg -font /usr/share/fonts/truetype/pointfree/pointfree.ttf -pointsize 15 -fill white -gravity SouthEast -strokewidth 3 -annotate +0+5 " #blabla.com " "output.jpg"
The problem with this is that when the background is light the text disappears.
I am aware that I could add a flag like
-undercolor '#00000080'
but I find this rather obtrusive, so looking for a better solution that make text's visiblily more independent of the background color. Note: image sizes are different so I can not hardcode the text's coordination.
Try this:
convert input.jpg -font /usr/share/fonts/truetype/pointfree/pointfree.ttf -pointsize 15 -gravity SouthEast -strokewidth 3 -fill black -annotate +2+7 " #blabla.com "-fill white -annotate +0+5 " #blabla.com " "output.jpg"
There was a post on the imagemagick forum from amember which took into consideration the colour under the text and produced a white or black watermark to suite. I was looking for it the otherday and could not find it. It was a batch script from memory.
I had to add the comment here as I was getting some message I did not understand about notifications when trying to add a comment.
Sorry I missed out a space here " #blabla.com "-fill should be " #blabla.com " -fill The command line is very long and would be easier to work with if you split it onto different lines.
Ok, finally I found a good batch solution:
for FILE in *.jpg; do convert $FILE -gravity southeast -stroke '#000C' -strokewidth 2 -annotate 0 'blabla.com' -stroke none -fill white -annotate 0 'blabla.com' $FILE; done
Related
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
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
I try to create a text image with ImageMagick, where is the stroke expands only outward. I found a solution, where I should use the "-draw" command, but with it I would need the size of my image, but I don't know it in advance.
The command below should be upgrated. Somehow I would need to draw the text again on it, without strokewidth:
convert -background none -fill white -pointsize 100 -stroke red \
-strokewidth 20 label:text stroke.png
#leu's solution almost good, but the positioning of the new text isn't in the good position. My result was that above, and I don't know, where I took a mistake:
My suggestion: combine label:"Some text" with -annotate "Some text". Like this:
#myfont="Arial-Black-Standard"
#myfont="Tahoma"
#offset="-0-0"
#offset="-20-10"
#offset="-30-10"
#offset="-10+10"
myfont="Tahoma"
offset="+10+10"
convert -respect-parentheses \
\( \
-font "${myfont}" \
-pointsize 180 \
-strokewidth 18 \
-fill blue \
-stroke blue \
-background none \
label:"Test text" \
\) \
-gravity center \
-font "${myfont}" \
-pointsize 180 \
-fill white \
-annotate "${offset}" "Test text" \
result${offset}.png
Play with the offset=... variable (also with the point sizes and stroke widths) to get closer to what you want. Here are some of my results:
However, like #MarkSetchell, I do not fully comprehend what you want to achieve. An explanation of what you mean by "outward stroke" that I do understand is missing...
yes: draw the same text onto your pic - maybe by piping output of your command to another convert
convert -background none -fill white -pointsize 100 -stroke red \
-strokewidth 20 label:text png:- \
| convert -fill white -pointsize 100 -stroke none \
-draw 'text 10,82 "text"' - stroke.png
the trick is to correctly place the second string. x-position is half the strokewidth, but y-position seems to be font- and pointsize-dependant. My approach was to first place both strings over each other when strokewidth was set to 0:
convert -background none -fill white -pointsize 100 -stroke red \
-strokewidth 0 label:text png:- \
| convert -fill white -pointsize 100 -stroke none \
-draw 'text 0,72 "text"' - stroke.png
then you have to add half the strokewidth to this y-position as well.
a bit of trial-and-error to get the correct y-position, but it seems to work for any string.
== edit ==
of course, we don't need to do trial-and-error. But instead we can use ImageMagick's power. Just perform the following steps (in this example within Bash):
#!/bin/bash
# read text from command line (or use "Test Text")
text=${1:-"Test Text"}
# strokewidth
sw=20
# pointsize
ps=120
# font
font=Arial
# result file
result="stroke.png"
# do some calc
sw_half=$(expr $sw / 2)
convert -background none -font $font -fill white -pointsize $ps -stroke red -strokewidth $sw label:"$text" $result
convert -background none -font $font -fill white -pointsize $ps -stroke none label:"$text" png:- | composite -geometry +${sw_half}+${sw_half} - $result $result
You can get the list of fonts available on your system by
convert -list font
The idea is the same as above: draw the text twice and draw one onto the other while using an offset of half the strokewidth.
The results all look like the following
I'm trying to convert a bunch of photos using imagemagick. However, I hadn't figured out how to overlay an image with gradient and write some text on it. I know the text part though:
convert IMG_8408.jpg \
-font URWChanceryMediumI \
-pointsize 250 \
-draw "gravity south
fill black text 0,40 'Some text stuff here'" \
test.jpg
Is there a way to add a white gradient to the bottom? Note, that the image size may vary.
What I have:
What I want:
I picked the colors so that it's clearly visible what I want to achieve
You can achieve desired output with 3 commands:
a. create the upper part of your image (a solid rectangle with your selected background color):
convert -size 640x200 xc:#A02B2B background.jpg
b. create another image containing the text over a gradient:
convert -size 640x110 gradient:#A02B2B-#126B27 -pointsize 25 -draw "gravity south fill black text 0,40 'Some text stuff here'" text.jpg
c. combine the images to obtain the final output:
montage background.jpg text.jpg -tile 1x2 -geometry +0+0 output.jpg
Note: I modified text creation parameters in step 2 to keep the command short, but you can add back your original settings
Use the following command:
magick -size 640x310 -define gradient:vector="0,107 0,0" gradient:"#a02b2b-#126b27" -flip -gravity south -font script-mt-bold -pointsize 48 -annotate +0+24 "Some text stuff here" output.png
I just recently started to explore ImageMagick and I have a doubt. I have been searching but could not find a solution.
With the following code:
convert -background lightblue -fill blue -font Candice -pointsize 30 \
-size 220x220 -gravity Center caption:'$txt' \
$name.gif
How do I use an image as background instead a static color?
I have tried -background "file.jpg" but it does not work.
Use -texture instead of -background.
I think I missunderstood your initial question. This will tile an image onto a set size background and add some text.
$txt = 'Caption';
// Tile the image - no background as it will not be seen behind the tile
$cmd = " -size 220x220 tile:noise.jpg -font Candice -fill blue -pointsize 30 ".
"-gravity Center -annotate +0+0 $txt";
exec("convert $cmd output.jpg");
Quite a few ways depending the effect you are after but this is one simple way:
convert input.jpg -fill blue -font Candice -pointsize 30 -gravity Center -annotate +0+0 "Some text" $name.gif
I can not get the hang of the way this site posts code :(