Page 1 of 1
Auto-Size problem
Posted: 2017-06-20T19:10:38-07:00
by gorby
This is probably a really nab question, so appologies in advance. I have searched for auto-size threads but they dont seem to be dealing with the same issue.
Im trying to write text from a file into an autosized box as per
http://www.imagemagick.org/Usage/annotating/ (the auto sized caption example)
Code: Select all
"width='identify -format %w test.png';convert -background '#0008' -fill white -gravity center -size ${width}x30 annotate text.txt test.png +swap -gravity North -geometry +0-3 -composite fort.jpg"
returns "convert: invalid argument for option `-size': identify @ error/convert.c/ConvertImageCommand/2791."
IF theres a simpler way to achieve this Id obviously just do that, Im just keep to use the auto size feature as Id like to cat a file on pictures in a script at a later point.
Thanks in advance.
Re: Auto-Size problem
Posted: 2017-06-20T19:15:31-07:00
by fmw42
What you need to do is use label: or caption: in "best fit" mode to create an overlay image that has text on a transparent background. Then composite that over your background image at the location you want. See
http://www.imagemagick.org/Usage/text/
http://www.imagemagick.org/Usage/layers/#convert
http://www.imagemagick.org/Usage/basics/#parenthesis
Here is an example:
Unix
Code: Select all
convert logo: \( -size 300x -background none -fill red -font arial label:"This Is Some Text" \) -gravity center -compose over -composite logo_with_text.jpg
Windows
Code: Select all
convert logo: ( -size 300x -background none -fill red -font arial label:"This Is Some Text" ) -gravity center -compose over -composite logo_with_text.jpg
Please always provide your IM version and platform/OS, since syntax differs.
Re: Auto-Size problem
Posted: 2017-06-21T08:17:30-07:00
by gorby
Thanks a lot for the reply. I re-read the stuff you linked with a view to doing what you suggested. Understanding the stuff about the parenthesis is helpful too, thanks. It took me a while to realise that "logo" in your example was the picture of the wizard dude, as I wasn't sure where it was coming from
Code: Select all
convert test.png \( -size 400x60 -background grey -fill red -font arial label:@/home/gorby/text \) -gravity northwest -compose over -composite logo_with_text.jpg
This is working well for me as I can just use sed to alter the text file contents so it fits nicely in the box.
Ive probably failed to understand some stuff, so might ask another question about stuff later if thats ok
Thanks for the help.
Im using $ convert.exe Version: ImageMagick 6.9.5-7 Q16 x86_64 2016-12-23
http://www.imagemagick.org in cygwin v 2.880 64
Re: Auto-Size problem
Posted: 2017-06-21T08:37:00-07:00
by snibgo
gorby wrote:width='identify -format %w test.png'
The page you linked to has:
Anthony wrote:width=`identify -format %w dragon.gif`
Can you see the difference? You set the variable to a string that starts with "identify", so when this is used in "-size", you get the error:
Code: Select all
invalid argument for option `-size': identify
You need to use backquotes, aka backticks, so your variable is set to the result of the identify command.