Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
-
lindylex
- Posts: 23
- Joined: 2014-02-27T16:36:22-07:00
- Authentication code: 6789
Post
by lindylex » 2017-03-08T23:23:27-07:00
I am trying to place the contents of a text file on top of a image. I am using caption because the documentation said it will add the necessary line breaks to match the dimension of the image.
This is from the on-line documentation.
http://www.imagemagick.org/Usage/text/#label :
"Best Fit Caption
As of IM v6.3.2, if you provide both the width and the height of the final image, but do not define the "-pointsize" of the font (or turn off the pointsize with "+pointsize"), IM will attempt to automatically adjust the size of the font so as to best fill the "-size" of the image you requested. "
Code: Select all
cat ./temp.txt | convert -background lightblue -fill blue -font /usr/share/fonts/truetype/freefont/FreeMonoBold.ttf -size 1000x1000 caption:@- cf.png
Error :
Code: Select all
convert-im6.q16: not authorized `@-' @ error/property.c/InterpretImageProperties/3516.
convert-im6.q16: no images defined `caption.png' @ error/convert.c/ConvertImageCommand/3258.
-
lindylex
- Posts: 23
- Joined: 2014-02-27T16:36:22-07:00
- Authentication code: 6789
Post
by lindylex » 2017-03-08T23:32:29-07:00
] SOLUTION SOLVED [
convert -background lightblue -fill blue -font /usr/share/fonts/truetype/freefont/FreeMonoBold.ttf -size 500x500 caption:"$(cat temp.txt)" -bordercolor lightblue -border 10 cf.png
-
fmw42
- Posts: 25751
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Post
by fmw42 » 2017-03-09T00:26:22-07:00
You can change your policy.xml if you do not care about outside security issues.
You can also do
Code: Select all
text=`cat ./temp.txt`
convert -background lightblue -fill blue -font /usr/share/fonts/truetype/freefont/FreeMonoBold.ttf -size 500x500 caption:"$text" -bordercolor lightblue -border 10 cf.png
-
lindylex
- Posts: 23
- Joined: 2014-02-27T16:36:22-07:00
- Authentication code: 6789
Post
by lindylex » 2017-03-13T14:31:02-07:00
fmw42 wrote: ↑2017-03-09T00:26:22-07:00
You can change your policy.xml if you do not care about outside security issues.
You can also do
Code: Select all
text=`cat ./temp.txt`
convert -background lightblue -fill blue -font /usr/share/fonts/truetype/freefont/FreeMonoBold.ttf -size 500x500 caption:"$text" -bordercolor lightblue -border 10 cf.png
fmw42, thanks for the response. I love your solution.
-
lindylex
- Posts: 23
- Joined: 2014-02-27T16:36:22-07:00
- Authentication code: 6789
Post
by lindylex » 2017-03-17T23:45:55-07:00
I am trying to overlay text onto this gradient and it is not working. It creates two images and none have the text caption.
Code: Select all
convert -size 1024x512 xc: +size xc:"#fb35fc" xc:"#603edb" \
-fx 'ar=hypot( i/w-.8, j/h-.3 )*4;
br=hypot( i/w-.3, j/h-.7 )*4;
u[1]*br/(ar+br) + u[2]*ar/(ar+br)' \
-fill '#ffffff' -font /usr/share/fonts/truetype/freefont/FreeMonoBold.ttf caption:"$(cat ./temp.txt)" -border 10\
i1.png
-
lindylex
- Posts: 23
- Joined: 2014-02-27T16:36:22-07:00
- Authentication code: 6789
Post
by lindylex » 2017-03-17T23:49:18-07:00
How do I pad the text without using the border command? I noticed the gradient does not cover the border.
-
snibgo
- Posts: 12412
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Post
by snibgo » 2017-03-18T07:14:48-07:00
lindylex wrote:It creates two images and none have the text caption.
You create three images, all with "xc:". Then "-fx" modifies the first and removes the others, so you have one image. Then you add a secoond image with "caption:". So your output has two images.
The second image contains your caption. But the text is small, and white on a white background.
-
lindylex
- Posts: 23
- Joined: 2014-02-27T16:36:22-07:00
- Authentication code: 6789
Post
by lindylex » 2017-03-18T19:31:14-07:00
snibgo, what you describe is what is happening. Can I do this all in one command, add the caption to the gradient?
snibgo wrote: ↑2017-03-18T07:14:48-07:00
lindylex wrote:It creates two images and none have the text caption.
You create three images, all with "xc:". Then "-fx" modifies the first and removes the others, so you have one image. Then you add a secoond image with "caption:". So your output has two images.
The second image contains your caption. But the text is small, and white on a white background.
-
snibgo
- Posts: 12412
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Post
by snibgo » 2017-03-18T21:47:22-07:00
I don't know what you want. The following makes a graduated image, a text image with transparent background, composites the text over the graduation, and puts a gray border around the result.
Code: Select all
convert \
-size 1024x512 xc: \
+size xc:"#fb35fc" xc:"#603edb" \
-fx 'ar=hypot( i/w-.8, j/h-.3 )*4;
br=hypot( i/w-.3, j/h-.7 )*4;
u[1]*br/(ar+br) + u[2]*ar/(ar+br)' \
-fill '#ffffff' \
-background None -gravity Center -pointsize 50 \
caption:"Hello world" \
-compose Over -composite \
-border 10 \
i2.png
It uses "-fx" so is very slow.
-
lindylex
- Posts: 23
- Joined: 2014-02-27T16:36:22-07:00
- Authentication code: 6789
Post
by lindylex » 2017-03-18T21:56:54-07:00
This is the closes I can get to making this happen in one line.
Code: Select all
convert -size 1000x1000 xc: +size xc:none -fill '#f5f21f' -font /usr/share/fonts/truetype/freefont/FreeMonoBold.ttf -size 1024x512 caption:"$(cat ./temp.txt)" xc:"#fb35fc" xc:"#603edb" \
-fx 'ar=hypot( i/w-.8, j/h-.3 )*4;
br=hypot( i/w-.3, j/h-.7 )*4;
u[1]*br/(ar+br) + u[2]*ar/(ar+br)' \
test.png
I did it using three commands.
Code: Select all
] Make Purple Gradient [
convert -size 1000x1000 xc: +size xc:"#fb35fc" xc:"#603edb" \
-fx 'ar=hypot( i/w-.8, j/h-.3 )*4;
br=hypot( i/w-.3, j/h-.7 )*4;
u[1]*br/(ar+br) + u[2]*ar/(ar+br)' \
i1.png
] Transparent [
convert -background 'rgba(0,0,0,0)' -fill '#ffffff' -font /usr/share/fonts/truetype/freefont/FreeMonoBold.ttf -size 950x950 caption:"$(cat ./temp.txt)" p1.png
] Overlay Text On Image [
convert i1.png p1.png -gravity center -composite r.png
This is the image.
https://unsee.cc/netupido/
ImageMagick version
Code: Select all
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114
-
fmw42
- Posts: 25751
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Post
by fmw42 » 2017-03-18T22:44:21-07:00
You need to use parenthesis processing to separate your commands. see
http://www.imagemagick.org/Usage/basics/#parenthesis
Code: Select all
convert \
\( -size 1000x1000 xc: +size xc:"#fb35fc" xc:"#603edb" \
-fx 'ar=hypot( i/w-.8, j/h-.3 )*4;
br=hypot( i/w-.3, j/h-.7 )*4;
u[1]*br/(ar+br) + u[2]*ar/(ar+br)' \) \
\( -size 950x950 -background 'rgba(0,0,0,0)' -fill '#ffffff' \
-font /usr/share/fonts/truetype/freefont/FreeMonoBold.ttf \
caption:"$(cat ./temp.txt)" \) \
-gravity center -composite r.png
or easier using directional gradient. See
http://www.imagemagick.org/script/gradient.php
Code: Select all
convert \
\( -size 1000x1000 -define gradient:direction=southwest \
gradient:"#fb35fc-#603edb" \) \
\( -size 950x950 -background none -fill white \
-font /usr/share/fonts/truetype/freefont/FreeMonoBold.ttf \
caption:"$(cat ./temp.txt)" \) \
-gravity center -composite r2.png
But since you did not provide your text file, it is hard to test the text wrapping. If you have line breaks in your text file, then things will not look correct.
You may also want to trim your text image result to its bounding box, since your text may not fill the entire height of the image.
-
lindylex
- Posts: 23
- Joined: 2014-02-27T16:36:22-07:00
- Authentication code: 6789
Post
by lindylex » 2017-03-18T23:26:44-07:00
fmw42, thanks your second solution run so fast and does exactly what I need.