Create CircleText on image with Imagemagick (convert) - imagemagick

I've a round image and I need to put some circle text on it.
The text is from the frontend where the preview is build with CircleType.js (http://circletype.labwire.ca/) a jQuery Plugin.
$("span#text").circleType({
radius: 102,
dir: -1
});
I checked http://www.imagemagick.org/Usage/fonts/ without a solution
currently I get this result
with the following code:
convert \
-background none \
-font Candice \
-pointsize 32 \
-fill navy label:\"A short TEST text\" \
-rotate 180 \
-distort Arc '270 180' \
outfile.png
but it isn't ever the same radius / distance to the border, base on the text length like in the first image.
Can somebody help me, please

Not sure exactly what you want, but you can hopefully see how to get there from this.
Like this maybe:
convert \
-background yellow \
-pointsize 64 \
-fill navy label:"A longer test text" \
-rotate 180 \
-distort arc '270 180' \
-trim +repage -resize 400x400 -gravity south -extent 400x400! outfile.png

Related

Bold Table Bars Removal using ImageMagick

I have an Invoice Image which contains table bars as below example.
I am using ImageMagick to pre-process Images using the below command.
convert 0.png -type Grayscale -negate -define morphology:compose=darken -morphology Thinning 'Rectangle:1x80+0+0<' -negate 0.png
My Problem is that output with horizontal bold bars. ImageMagick fails to convert it correctly and output as below.
What can I do to solve this?
Here is a different way using ImageMagick and connected components. First trim the image to remove the outer white, then use connected components to get the id of the largest black region, which should be id=0. The run it again removing the id of the largest area making it transparent and finally flattening the result against white. Then add the thinning operation to remove the horizontal lines that were not fully black. See https://imagemagick.org/script/connected-components.php
convert image.png -fuzz 5% -trim +repage \
-bordercolor black -border 1 \
-define connected-components:verbose=true \
-define connected-components:mean-color=true \
-connected-components 4 \
null:
Objects (id: bounding-box centroid area mean-color):
0: 953x205+0+0 478.7,65.6 31513 srgba(0,0,0,1)
10789: 943x19+5+184 488.4,193.1 16885 srgba(255,255,255,1)
1: 465x17+5+1 237.0,9.0 7905 srgba(255,255,255,1)
2: 474x17+474+1 733.5,9.0 7096 srgba(255,255,255,1)
3820: 281x21+667+67 807.0,76.9 5609 srgba(255,255,255,1)
5195: 281x21+667+90 807.0,99.9 5609 srgba(255,255,255,1)
7959: 281x20+667+137 807.0,146.4 5328 srgba(255,255,255,1)
9341: 281x20+667+160 807.0,169.5 5328 srgba(255,255,255,1)
6540: 281x20+667+114 807.0,123.4 5295 srgba(255,255,255,1)
2375: 281x19+667+46 807.0,55.0 5047 srgba(255,255,255,1)
...
convert image.png -fuzz 5% -trim +repage \
-bordercolor black -border 1 \
-define connected-components:remove=0 \
-define connected-components:mean-color=true \
-connected-components 4 \
-background white -flatten \
-negate \
-define morphology:compose=darken \
-morphology Thinning 'Rectangle:1x80+0+0<' \
-negate \
result.png

ImageMagick: How to resize proportionally with mogrify without a background

I was following this example http://cubiq.org/create-fixed-size-thumbnails-with-imagemagick, and it's exactly what I want to do with the image, with the exception of having the background leftovers (i.e. the white borders). Is there a way to do this, and possibly crop the white background out? Is there another way to do this? The re-size needs to be proportional, so I don't just want to set a width re-size limit or height limit, but proportionally re-size the image.
The example you link to uses this command:
mogrify \
-resize 80x80 \
-background white \
-gravity center \
-extent 80x80 \
-format jpg \
-quality 75 \
-path thumbs \
*.jpg
First, mogrify is a bit dangerous. It manipulates your originals inline, and it overwrites the originals. If something goes wrong you have lost your originals, and are stuck with the wrong-gone results. In your case the -path thumbs however alleviates this danger, because makes sure the results will be written to sub directory thumbs
Another ImageMagick command, convert, can keep your originals and do the same manipulation as mogrify:
convert \
input.jpg \
-resize 80x80 \
-background white \
-gravity center \
-extent 80x80 \
-quality 75 \
thumbs/output.jpg
If want the same result, but just not the white canvas extensions (originally added to make the result a square 80x80 image), just leave away the -extent 80x80 parameter (the -background white and gravity center are superfluous too):
convert \
input.jpg \
-resize 80x80 \
-quality 75 \
thumbs/output.jpg
or
mogrify \
-resize 80x80 \
-format jpg \
-quality 75 \
-path thumbs \
*.jpg
I know this is an old thread, but by using the -write flag with the -set flag, one can write to files in the same directory without overwriting the original files:
mogrify -resize 80x80 \
-set filename:name "%t_small.%e" \
-write "%[filename:name]" \
*.jpg
As noted at http://imagemagick.org/script/escape.php, %t is the filename without extension and %e is the extension. So the output of image.jpg would be a thumbnail image_small.jpg.
This is the command I use each time I want to batch resized everything to 1920x and keep aspect ratio.
mogrify -path . -resize 1920x1920 -format "_resized.jpg" -quality 70 *.jpg

GraphicsMagick - position item in bottom left

After trying every combination of commands that I could possibly think of I still can't get this to work.
I have a large image that can vary in size: Logo.png
I have a small image of a 'known' size: Wallpaper.png
I want Logo to appear in the Bottom Left of Wallpaper.
This has to be done using the 'gm convert' command using -flatten. Using 'gm composite' would require me to run two commands which isn't acceptable as it would add too much time to our processing per image.
Here is the command so far (there will be more added to this command but here is the core of it):
wallpaper.png -page +0+0 -gravity SouthWest logo.png -compose over -flatten result.jpg
This puts the logo in the top left. Gravity appears to be ignored. Using +100% for -page does not work either.
I don't see the need for your use of -flatten and +page
The following ImageMagick command should work:
convert \
-composite \
-geometry +10+20 \
-gravity southwest \
background.png \
logo.png \
result.png
For GraphicsMagick this needs to change to:
gm \
composite \
-geometry +10+20 \
-gravity southwest \
logo.png \
background.png \
result.png
I added +10+20 to demonstrate how you can offset the overlaid logo a little bit from the extreme lower left corner.

Transparent PNGs and a JPEG combine in ImageMagick

I have a case where I need to combine two transparent layers on top of JPEG files.
Here a sample setup:
wget -O bg.jpg http://www.grahamowengallery.com/photography/Flowers/roadside-flowers.jpg
wget -O layer.png http://www2.picturepush.com/photo/a/6271450/640/TRANSPARENT-EMBELLISHMENTS/pink-flower-transparent-png.png
wget -O logo.png http://upload.wikimedia.org/wikipedia/commons/0/0d/Imagemagick-logo.png
I can get desired result with commands:
composite bg.jpg \( -compose Overlay layer.png \) bg2.jpg
composite bg2.jpg \( -compose Overlay logo.png \) result.jpg
This is good, but I want to avoid writing bg2.png to drive.
I tried:
composite bg.jpg \( -compose Overlay layer.png \) \( -compose Overlay logo.png \) result2.jpg
but this results on layer.png on black background. How can I fix this?
I couldn't make composite working, but convert works:
convert.exe bg.jpg layer.png -compose Overlay -composite logo.png -compose Overlay -composite result2.jpg
Further reading: http://www.imagemagick.org/Usage/compose/
I can not test this at the moment but you may be able to use layers merge and you should be able to use the URLs in your code.
$cmd = "http://www.grahamowengallery.com/photography/Flowers/roadside-flowers.jpg ".
" http://www2.picturepush.com/photo/a/6271450/640/TRANSPARENT-EMBELLISHMENTS/pink-flower-transparent-png.png ".
" http://upload.wikimedia.org/wikipedia/commons/0/0d/Imagemagick-logo.png -layers merge ";
exec(" convert $cmd result.jpg ");
You are not using any positioning for your layers - are you going to introduce that later? If so you can add -page +0+0 in front of each image to locate them where you want. +0+0 would be changed to the location.

Image Magick - Converting text to image - is there a way to center the text to the middle of the image?

I have a simple text file that reads something like "It is 28 degrees today" I am trying to use imagemagick to center it to the middle of the image. The command i am using is this right now
`convert -background lightblue -fill blue -size 165x70 filename.txt image.png`
I tried using gravity but it always put the text outside of the image for some reason. I am not using it correctly from what I can see. I would like it to be centered. Any suggestions?
convert \
-size 165x70 \
xc:lightblue \
-font Bookman-DemiItalic \
-pointsize 12 \
-fill blue \
-gravity center \
-draw "text 0,0 'It is 28 degrees today'" \
image.png
If you want to pull the input from an existing file, just feed that to the draw command:
convert \
-size 165x70 \
xc:lightblue \
-font Bookman-DemiItalic \
-pointsize 12 \
-fill blue \
-gravity center \
-draw "text 0,0 '$(cat file.txt)'" \
image.png
Look At this
convert temp.jpg -gravity Center -pointsize 30 -annotate 0 'Love you
mom' temp1.jpg
'i love u mom' text word
gravity positioning center place of the text

Resources