I have a batch of images that need a transparent background. I am able to create a black/white mask of the lighter and darker regions and want to use this mask to keep the pixels, which are white in the mask unchanged and set all pixel to transparent, which are black. The best outcome so far I got with
convert $FILE -rotate "-90<" $ROTATED
convert $ROTATED \
+dither \
-colors 2 \
-fill black \
-draw 'color 0,0 floodfill' \
-flop \
-draw 'color 0,0 floodfill' \
-flop \
-white-threshold 0 \
$MASK
convert $ROTATED -mask $MASK -compose copy-opacity -composite $OUT
But the last command just "ghosts" the whole image. How can I "cut out" the black pixels and keep the white pixels unchanged?
This is what I get so far.
You simply need to remove the "-mask" from your command line leaving your mask image (and add -alpha off). So the following works fine for me in ImageMagick 6.
Input:
convert star.png \
+dither \
-colors 2 \
-fill black \
-draw 'color 0,0 floodfill' \
-flop \
-draw 'color 0,0 floodfill' \
-flop \
-white-threshold 0 \
mask.png
convert star.png mask.png -alpha off -compose copy-opacity -composite out.png
Mask:
Result:
Download the result to see that the background is fully transparent.
If using Imagemagick 7, then change convert to magick
ADDITION
Here is one way to do that with MPR. Note the +swap.
convert star.png \
-write mpr:star \
+dither \
-colors 2 \
-fill black \
-draw 'color 0,0 floodfill' \
-flop \
-draw 'color 0,0 floodfill' \
-flop \
-white-threshold 0 \
mpr:star \
+swap \
-alpha off \
-compose copy-opacity -composite \
out.png
You can also do it with a clone and parentheses.
convert star.png \
\( +clone \
+dither \
-colors 2 \
-fill black \
-draw 'color 0,0 floodfill' \
-flop \
-draw 'color 0,0 floodfill' \
-flop \
-white-threshold 0 \) \
-alpha off \
-compose copy-opacity -composite \
out.png
I get the same result as above.
Hi I am having trouble with what I am creating using Imagemagick.
Here's the scripts:
convert
-size 300x300 xc:skyblue
-background none
-fill #AF280E
-stroke none
-draw "circle 150,150 75,250"
-fill white
-stroke none
-draw "circle 150,150 75,240"
-fill #D3DADF
-stroke none
-draw 'path "M 260 150 A 1 1,0,0 ,1 ,41 150"'
-fill #AF280E
-stroke none
-draw 'path "M 260 150 A 1 1,0,0 ,0 ,41 150"'
-fill white
-stroke none
-draw "rectangle 290,140 10,170"
-fill white
-stroke #AF280E
-strokewidth 5
-draw "line 10,137 290,137"
-strokewidth 40
-fill white
-stroke #D3DADF
-strokewidth 5
-draw "line 10,170 290,170"
-strokewidth 40
-fill white
-stroke none
-annotate 100,50
-draw "circle 150,150 75,150"
-background none
-font Bookman-Light
-pointsize 12
-fill navy label"arc text here"
-distort Arc 340
logo_2_b6.gif
I wanted to place the arc text over those circles but it keeps on blinking and seems even the shapes created where arc too.
You have several mistakes in your command line with ImageMagick commands.
Lets write this a bit more readable and add writing of temp files after each step. This is Unix syntax for your code:
convert -size 300x300 xc:skyblue +write t1.png \
-background none -fill #AF280E -stroke none -draw "circle 150,150 75,250" +write t2.png \
-fill white -stroke none -draw "circle 150,150 75,240" +write t3.png \
-fill #D3DADF -stroke none -draw 'path "M 260 150 A 1 1,0,0 ,1 ,41 150"' +write t4.png \
-fill #AF280E -stroke none -draw 'path "M 260 150 A 1 1,0,0 ,0 ,41 150"' +write t5.png \
-fill white -stroke none -draw "rectangle 290,140 10,170" +write t6.png \
-fill white -stroke #AF280E -strokewidth 5 -draw "line 10,137 290,137" +write t7.png \
-strokewidth 40 -fill white -stroke #D3DADF -strokewidth 5 -draw "line 10,170 290,170" +write t8.png \
-strokewidth 40 -fill white -stroke none -annotate 100,50 +write t9.png \
-draw "circle 150,150 75,150" +write t10.png \
-background none -font Bookman-Light -pointsize 12 -fill navy label:"arc text here" +write t11.png \
-distort Arc 340 logo_2_b6.gif
Here I have fixed your code:
convert -size 300x300 xc:skyblue +write t1.png \
-background none -fill "#AF280E" -stroke none -draw "circle 150,150 75,250" +write t2.png \
-fill white -stroke none -draw "circle 150,150 75,240" +write t3.png \
-fill "#D3DADF" -stroke none -draw 'path "M 260 150 A 1 1,0,0 ,1 ,41 150"' +write t4.png \
-fill "#AF280E" -stroke none -draw 'path "M 260 150 A 1 1,0,0 ,0 ,41 150"' +write t5.png \
-fill white -stroke none -draw "rectangle 290,140 10,170" +write t6.png \
-fill white -stroke "#AF280E" -strokewidth 5 -draw "line 10,137 290,137" +write t7.png \
-strokewidth 40 -fill white -stroke "#D3DADF" -strokewidth 5 -draw "line 10,170 290,170" +write t8.png \
-strokewidth 40 -fill white -stroke none -annotate +100+50 " " +write t9.png \
-draw "circle 150,150 75,150" +write t10.png \
-background none -font Arial -pointsize 12 -fill navy label:"arc text here" -compose over -composite +write t11.png \
-distort Arc 340 logo_2_b6.gif
First, your line that ends in +write t9.png makes no sense to me. The -annotate syntax is -annotate +X+Y "some text". You have the wrong syntax for the +X+Y (you have X,Y). Second you have no text. What are you trying to do? See my equivalent line ending in t9.png. I have corrected your syntax and added some empty text, since I do not know what you are trying to do here.
Second and what fails is your label. It must be label:"some text". You left off the colon (:).
Third, that line causes you to have two versions of t11.png, namely, t11-0.png and t11-1.png. Label creates a new image. It does not write on the previous image. So you need to add -compose over -composite for it to show in a single t11.png
It also helps to look at each image created to see if it is producing the correct result for that step.
So what I get from my command is:
As fmw42 mentioned, there are several problems with your command. Consider a few improvements...
A single setting for things like fill color, stroke color, and strokewidth will work on all following operations until you need to change them. You don't have to do it that way, but it can help keep your code less cluttered.
Make your label and do the arc distort it inside parentheses to avoid distorting the rest of the logo you created earlier in the command. It's also helpful to specify the outside and maybe inside radii in that "-distort arc" operation when you make the curved text.
Your output is a GIF, so you need to "-composite" the text onto the logo graphic before writing the output, otherwise IM will make an animated GIF and your text will be blinking.
Here is a command that works for me on IMv6.8.9 running in a bash shell. It might help get you going in a good direction...
convert -size 300x300 xc:skyblue +size -background none \
-stroke none \
-fill "#AF280E" -draw "circle 150,150 75,250" \
-fill white -draw "circle 150,150 75,240" \
-fill "#D3DADF" -draw 'path "M 260 150 A 1 1,0,0 ,1 ,41 150"' \
-fill "#AF280E" -draw 'path "M 260 150 A 1 1,0,0 ,0 ,41 150"' \
-fill white -draw "rectangle 290,140 10,170" \
-strokewidth 5 \
-fill white \
-stroke "#AF280E" -draw "line 10,137 290,137" \
-stroke "#D3DADF" -draw "line 10,170 290,170" \
-strokewidth 40 \
-stroke none -draw "circle 150,150 75,150" \
+strokewidth \
\( -font Bookman-Light -pointsize 36 -fill navy -virtual-pixel none \
label:"arc text here" -distort Arc "340 0 68" \) \
+repage -gravity center -composite logo_2_b6.gif
EDITED TO ADD:
I added another "label:" and adjusted the radius to make a second piece of text and make it compatible with the first. It has to be rotated before the arc distort to make the lettering proper side up.
convert -size 300x300 xc:skyblue +size -background none \
-stroke none \
-fill "#AF280E" -draw "circle 150,150 75,250" \
-fill white -draw "circle 150,150 75,240" \
-fill "#D3DADF" -draw 'path "M 260 150 A 1 1,0,0 ,1 ,41 150"' \
-fill "#AF280E" -draw 'path "M 260 150 A 1 1,0,0 ,0 ,41 150"' \
-fill white -draw "rectangle 290,140 10,170" \
-strokewidth 5 \
-fill white \
-stroke "#AF280E" -draw "line 10,137 290,137" \
-stroke "#D3DADF" -draw "line 10,170 290,170" \
-strokewidth 40 \
-stroke none -draw "circle 150,150 75,150" \
+strokewidth \
-gravity center \
\( -font Bookman-Light -pointsize 48 \
-fill "#D3DADF" -virtual-pixel none \
label:"\ upper arc " \
-distort Arc "360 0 115" \) \
-gravity center \
+repage -composite \
\( -font Bookman-Light -pointsize 48 \
-fill navy -virtual-pixel none \
label:"\ lower arc " \
-rotate 180 -distort Arc "360 180 115" \) \
+repage -composite logo_2_b8.gif
It can be extremely challenging to work with areas of curved text in ImageMagick. Notice I had to add spaces and do rotations to make sure both text labels matched each other in size and location of center. Different fonts, varying amounts of text, and even using the same font name on different machines can all affect the exact placement of text.
It might be helpful to study the "Circular and Radial Distortion" operations for some help creating and aligning circular images.
I want to create image watermark like Shutterstock. I have tried but not able to replicate it. I tried with the following command. The issue is for me is i not able to add diagonal random text to image as Shutterstock does. I have tried many options with no luck.
infile="zoom.jpg"
ww=$(convert -ping "$infile" -format "%[fx:w-1]" info:)
hh=$(convert -ping "$infile" -format "%[fx:h-1]" info:)
convert "$infile" \
-fill "graya(100%,0.75)" \
-draw "line 0,0 $ww,$hh line $ww,0 0,$hh" -alpha off \
-fill "graya(50%,0.25)" \
tile_aqua_500_text_x_text.jpg
composite -dissolve 35 -gravity center logo.png tile_aqua_500_text_x_text.jpg tile_aqua_500_text_x_text.jpg
convert -background none -size 220x320 xc:none -font DejaVu-Sans-Bold -pointsize 30 \
-gravity North -draw "rotate -22 fill grey text 20,10 'knot9'" \
-gravity West -draw "rotate -27 fill grey text 5,15 '89898989'" \
miff:- |\
composite -dissolve 70 -tile - tile_aqua_500_text_x_text.jpg tile_aqua_500_text_x_text.jpg
width=`identify -format %w tile_aqua_500_text_x_text.jpg`; \
convert -background '#0008' -fill white -gravity center -size ${width}x30 -pointsize 10 -font DejaVu-Sans-Bold\
caption:"\nThis image is Copyrighted by Knot9 \n www.knot9.com | Image Id: 89898989\n" \
tile_aqua_500_text_x_text.jpg +swap -gravity south -composite tile_aqua_500_text_x_text.jpg
My Output is
Requirement is
In ImageMagick, you can do the following. Create a small text image on a transparent background using label:. Rotate it. Pad it to control the spacing. Tile it out to fill the image. Then composite the tiled out image over your background image.
Image:
convert lena.png \
\( -size 100x -background none -fill white -gravity center \
label:"watermark" -trim -rotate -30 \
-bordercolor none -border 10 \
-write mpr:wm +delete \
+clone -fill mpr:wm -draw 'color 0,0 reset' \) \
-compose over -composite \
lena_watermark.png
If using ImageMagick 7, then change convert to magick
See https://imagemagick.org/Usage/canvas/#tile_memory for tiling
While searching google, we see a lot of images with a text overlay effect that claim these images are coming from shutterstock.com.
This text effect is something like the following:
https://thumb7.shutterstock.com/display_pic_with_logo/4187557/559982074/stock-vector-few-little-houses-in-the-winter-forest-landscape-flat-style-vector-seamless-pattern-559982074.jpg
I am wondering how can I use ImageMagick cli to do something similar?
Thank you very much for any help.
Ideally, you would create a watermark mask with the text effect, and composite over the source image.
Step 1: Create text effect for reuse
convert -pointsize 64 -font GeorgiaB \
-fill black -stroke white -strokewidth 2 \
-background transparent -channel A -evaluate subtract 75% \
caption:"Hello World" mask.png
Step 2: Composite text effect over other images
convert -size 500x400 plasma: mask.png \
-gravity center -compose ATop -composite output.png
There's a lot more examples of text handling & effects, as well as composite techniques over # Anthony's Usage documentation.
There are many ways to add a white area at the bottom with text. This is one. If that is not what you want, then please explain further.
infile="tile_aqua_500.jpg"
ww=$(convert -ping "$infile" -format "%[fx:w-1]" info:)
hh=$(convert -ping "$infile" -format "%[fx:h-1]" info:)
convert "$infile" \
-fill "graya(100%,0.75)" \
-draw "line 0,0 $ww,$hh line $ww,0 0,$hh" -alpha off \
-fill "graya(50%,0.25)" \
-strokewidth 1 -stroke "graya(100%,0.25)" \
-gravity center -font arial -pointsize 48 \
-annotate +0+0 "Hello World" \
-undercolor white -gravity southeast -pointsize 24 \
-fill black -annotate +10+10 "yourdomain.com" \
tile_aqua_500_text_x_text.jpg
Hi fmw42, thank you :) How can I add a big X like shutterstock.com?
Draw two diagonal lines between the corners.
Input (tile_aqua_500.jpg) :
In Imagemagick 6 Unix system:
infile="tile_aqua_500.jpg"
ww=$(convert -ping "$infile" -format "%[fx:w-1]" info:)
hh=$(convert -ping "$infile" -format "%[fx:h-1]" info:)
convert "$infile" \
-fill "graya(100%,0.75)" \
-draw "line 0,0 $ww,$hh line $ww,0 0,$hh" -alpha off \
-fill "graya(50%,0.25)" \
-strokewidth 1 -stroke "graya(100%,0.25)" \
-gravity center -font arial -pointsize 48 \
-annotate +0+0 "Hello World" tile_aqua_500_text_x.jpg
In Imagemagick 7 Unix system:
infile="tile_aqua_500.jpg"
magick "$infile" \
-fill "graya(100%,0.75)" \
-draw "line 0,0 %[fx:w-1],%[fx:h-1] line %[fx:w-1],0 0,%[fx:h-1]" -alpha off \
-fill "graya(50%,0.25)" \
-strokewidth 1 -stroke "graya(100%,0.25)" \
-gravity center -font arial -pointsize 48 \
-annotate +0+0 "Hello World" tile_aqua_500_text_x.jpg
Result of either command:
Here is an alternate method to the excellent one from emcconville using Imagemagick -annotate to draw text directly on an image. I start with a small tillable image that I enlarge to 500x500 in size, before drawing the text with 50% transparency in mid gray and with a 50% transparent white outline. You can change the shades of gray and transparency as desired along with the font and pint-size. Change +0+0 to shift the locations of the text relative to the gravity center. Change -gravity to other compass locations to draw the text relative to those locations.
convert -size 500x500 tile:tile_aqua.jpg \
-fill "graya(50%,0.5)" -strokewidth 1 -stroke "graya(100%,0.5)" \
-gravity center -font arial -pointsize 64 \
-annotate +0+0 "Hello World" result.jpg
convert -size 500x500 tile:tile_aqua.jpg \
-fill "graya(50%,0.25)" -strokewidth 1 -stroke "graya(100%,0.25)" \
-gravity southeast -font arial -pointsize 48 \
-annotate +50+50 "Hello World" result1.jpg
I am new to ImageMagick and I am trying to add 3 different labels to 3 different (small) images, and then insert them over a background image, each being in a corner.
All of the images, and text strings are unknown before-hand and that's why I'm writing a script to handle this. My latest (failed) attempt is:
convert -page +0+0 ${bg}.png \
\( -page +0+0 -gravity south -pointsize 16 \
-stroke '#000C' -strokewidth 4 -annotate 0 "$label" \
-stroke none -strokewidth 20 -fill white -annotate 0 "$label" \) \
\( -page +0+0 ${im1}.png \
-stroke '#000C' -strokewidth 2 -annotate 0 "text1" \
-stroke none -fill white -annotate 0 "text1" \) \
\( -page +${hor_offset}+0 {im2}.png \
-gravity south -pointsize 14 \
-stroke '#000C' -strokewidth 2 -annotate 0 "text2" \
-stroke none -fill white -annotate 0 "text2" \) \
\( -page +0+${ver_offset} ${im3}.png \
-stroke '#000C' -strokewidth 2 -annotate 0 "text3" \
-stroke none -fill white -annotate 0 "text3" \) \
+page -flatten out.png
I have had a better result earlier, but it was mainly by chance and decided to seek an expert's help.
The final result should look something like this: Expected result
-page does not respect -gravity. -page is always relative to the northwest corner (top-left) of the image. You can alternately, use -gravity and -geometry with -composite in pairs. Create one image, then composite over the background in the correct location. The repeat with that result and another image to overlay. See http://www.imagemagick.org/Usage/layers/#convert