Page 1 of 1

Caption failed adding text from file to image

Posted: 2017-03-08T23:23:27-07:00
by lindylex
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.

Re: Caption failed adding text from file to image

Posted: 2017-03-08T23:32:29-07:00
by lindylex
] 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

Re: Caption failed adding text from file to image

Posted: 2017-03-09T00:26:22-07:00
by fmw42
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

Re: Caption failed adding text from file to image

Posted: 2017-03-13T14:31:02-07:00
by lindylex
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.

Re: Caption failed adding text from file to image

Posted: 2017-03-17T23:45:55-07:00
by lindylex
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

Re: Caption failed adding text from file to image

Posted: 2017-03-17T23:49:18-07:00
by lindylex
How do I pad the text without using the border command? I noticed the gradient does not cover the border.

Re: Caption failed adding text from file to image

Posted: 2017-03-18T07:14:48-07:00
by snibgo
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.

Re: Caption failed adding text from file to image

Posted: 2017-03-18T19:31:14-07:00
by lindylex
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.

Re: Caption failed adding text from file to image

Posted: 2017-03-18T21:01:43-07:00
by fmw42
What are you expecting the output to look like? Please describe in detail regarding the size of the 3 images and how they should look when combined?

Please, always provide your IM version and platform when asking questions, since syntax may differ. Also provide your exact command line and if possible your images.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at viewtopic.php?f=1&t=9620

For novices, see

viewtopic.php?f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/

Re: Caption failed adding text from file to image

Posted: 2017-03-18T21:47:22-07:00
by snibgo
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.

Re: Caption failed adding text from file to image

Posted: 2017-03-18T21:56:54-07:00
by lindylex
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 

Re: Caption failed adding text from file to image

Posted: 2017-03-18T22:44:21-07:00
by fmw42
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.

Re: Caption failed adding text from file to image

Posted: 2017-03-18T23:26:44-07:00
by lindylex
fmw42, thanks your second solution run so fast and does exactly what I need.