I have a command like this:
convert -font Tahoma -pointsize 20 label:' Around the World ' \
-virtual-pixel Background -background SkyBlue \
-distort Arc 60 arc_circle_1.png
The command will create an image:
The background of the text is white, I want it to be transparent. How can I do that? Tkanks.
Normally, you would do that by setting the undercolor, like this:
convert -undercolor magenta -font Tahoma -pointsize 20 label:' Around the World ' -virtual-pixel Background -background SkyBlue -distort Arc 60 arc_circle_1.png
but for some reason, that doesn't work when you set the undercolour to none or transparent because you can't overdraw with nothing to make something.
All I can suggest for the minute, is that you create the image with the default white undercolour, then make whites transparent:
convert -font Tahoma -pointsize 20 label:' Around the World ' -virtual-pixel Background -background SkyBlue -distort Arc 60 -fuzz 20% -transparent white arc_circle_1.png
If you have whites in your image somewhere, just set the undercolour to fucshia or something very contrasting and later, make that colour transparent.
Related
I am using imagemagick to draw a border on the top of an image.
THIS IS MY CODE:
convert source.jpg -stroke red -strokewidth 2 -fill transparent -draw \"roundrectangle 10,10 628,151 10,10\" source.jpg
This works fine but i need to be able to position the -draw where i want.
I tried to position the border like using -geometry like so:
convert source.jpg -stroke red -strokewidth 2 -fill transparent -geometry +5+15 -draw \"roundrectangle 10,10 628,151 10,10\" source.jpg
But this does not position it where i want. I also tried using -gravity and that doesn't work either!
Could someone please advise on this?
Thanks in advance.
Bonzo is correct, you cannot use -geometry with -draw.
In ImageMagick with -draw you can also translate to where you want the center to be and then specify +- distances to the corners from the center placement.
Suppose you have a 100x100 size box you want draw and you want it centered at 250,250, then
convert input.jpg -stroke red -strokewidth 2 -fill transparent -draw "translate 250,250 roundrectangle -50,-50 50,50 10,10" output.png
That makes it easier to draw the same size boxes at different locations.
see
http://www.imagemagick.org/Usage/draw/
http://www.imagemagick.org/script/magick-vector-graphics.php
I am using Image Magick to overlay a dimmed caption to an image, with IM automatically choosing the best fontsize:
convert -background '#0008' -fill white -geometry +0+330 -size 370x60 caption:$title $image +swap -composite $imageOutput
My problem is that there is not enough space around the text, I would like to add some "padding". I usually do that with the -border option but if I add this to my command above, the caption is not dimmed anymore.
Do you have a solution to create a dimmed caption with enough room around the text?
I have a solution, but it's a bit of a kludge because I had trouble extending or bordering a semi-transparent background. In the end, I just constructed the caption on a black background and bordered it in black, then I tweaked the alpha channel afterwards:
convert -background black -bordercolor black -fill white \
-size 370x60 caption:"This is the title" \
-trim -border 20 -channel A -fx '(lightness/2)+.5' \
-geometry +0+200 background.gif +swap -composite result.png
The only tricky part is -channel A -fx .... The first part means that we are only affecting/modifying the alpha/opacity channel. The 0.5 means that all pixels become at least 50% opaque, and (lightness/2) means that absolutely white pixels, i.e. your lettering, (which will have a lightness of 1) become fully opaque because 0.5+(1/2) totals to one. The point of this is to preserve the anti-aliasing around the edges of the letters to some degree.
Here is my code:
#! /usr/bin/env sh
# Generate test image.
convert -size 100x60 xc:blue -fill blue -stroke black -draw "circle 50,30 55,55" in.png
# Make background transparent.
convert in.png -fill none -draw 'matte 0,0 floodfill' -flop -draw 'matte 0,0 floodfill' -flop out.png
# Replace transparent background with green.
mogrify -background green -flatten out.png
# The wrong way.
convert in.png -transparent blue oops.png
mogrify -background green -flatten oops.png
It is based on this snippet: https://snippets.aktagon.com/snippets/558-how-to-remove-a-background-with-imagemagick
Starting with this:
I want to get this:
Not this:
Can I achieve this with a single convert command instead of a convert followed by a mogrify?
I am using ImageMagick 6.8.9-9.
Essentially, you are seeking a "floodfill", like this:
convert in.png -fill green -draw 'color 0,0 floodfill' result.png
That will look at the top-left pixel (0,0) and fill all similarly coloured pixels which are connected to it with green. If your background has slight variations in it, e.g. it's a JPEG, add some fuzz factor
convert in.jpg -fuzz 25% ...
Note that if your circle had touched the top and bottom edges, it would prevent the fill from flooding around to the right side of the diagram. So, let's say you had created your circle like this:
convert -size 100x60 xc:blue -fill blue -stroke black -draw "circle 50,30 50,0" in.png
And then you run the above command, you will get:
If that happens, you can add a single pixel wide border all the way around for the colour to "flow" through first, then flood-fill, and finally remove it later:
convert in.png -bordercolor blue -border 1 -fill green -draw 'color 0,0 floodfill' -shave 1x1 result.png
I'm using ImageMagick ver 6.9.3-7 to write text over pictures. I've noticed that the same text with the same font looks much better in html canvas and I'm trying to make it looks the same.
This is how it looks in the html5 canvas:
and this is how it's looks with IM:
(enlarge the images to view the different)
This is how I'm creating the image with node.js:
gmFrame
.font("./assets/impact.ttf", fontSize)
.stroke("#000")
.strokeWidth(8)
.draw(`gravity center text ${position.x},${position.y} '${text}'`)
.stroke("transparent")
.fill("#fff")
.draw(`gravity center text ${position.x},${position.y} '${text}'`);
Is there something to do about it?
After investigating the only way to do it is with blur.
This is an example for how to add text with blur without writing another file
convert -quality 100 "DJ Pauly D.jpg" -resize 500x500 \( +clone -alpha transparent -pointsize 52 -font impact -stroke "#000" -strokewidth 8 -draw "gravity center text 0,0 'WRITE SOMETHING'" -stroke "transparent" -fill "#fff" -draw "gravity center text 0,0 'WRITE SOMETHING'" -blur 0x5 \) -composite r2.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 :(