How do I convert text file to image for use with overlay

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?".
whenry

How do I convert text file to image for use with overlay

Post by whenry »

I need to provide image files to my users which replace the current practice of printing on preprinted forms. I have scanned the form and saved it as a PNG with transparency where needed and I can combine it with an image file using composite. I have not been able to understand/use convert to create an image file from my existing text file (the data that normally prints on the preprinted form) to composite with my 'blank' form. I have tried variations on CONVERT with the TEXT: option but I simply do not know enough and cannot find where to go, to understand what options should be used. I have read the IM examples but apparently do not have a good enough overall understanding to be able to use what they are telling me.

Thank you in advance for your help and consideration of my newbie-ness .
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How do I convert text file to image for use with overlay

Post by fmw42 »

can you provide links to your input form, your text file and an example (or description) of what you want the result to look like.

If you are trying to put specific text into different locations on the form page, then you will need to create an image using label: or caption: or -annotate or -draw for each one and then composite each into the right location on your form.

see http://www.imagemagick.org/Usage/text/
whenry

Re: How do I convert text file to image for use with overlay

Post by whenry »

I am not trying to use IM to position. I will use good old fashioned placement by the fixed font as is being done now when it prints currently. I can supply samples if required but it should not make a difference. Just take any text file of multiple lines and show me how to construct a command which will convert that to a image using a fixed font of specified size and I will be thrilled.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How do I convert text file to image for use with overlay

Post by fmw42 »

convert -size 500x500 -fill black -font Helvetica caption:@text.txt text.gif
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How do I convert text file to image for use with overlay

Post by snibgo »

A more complex example:

Code: Select all

convert -size 1920x1080 -gravity Center -backgound none -fill black -strokewidth 2 -stroke red -font Verdana -density 96 -pointsize 56 caption:@capt.txt out.png
snibgo's IM pages: im.snibgo.com
whenry

Re: How do I convert text file to image for use with overlay

Post by whenry »

Ah ha , the light dawns dimly. Thanks I was really confused about the caption:@(or -) form and what that meant. I think I see.

Why do y'all suggest 'caption:' not 'text:' ? Text seems more like what I am trying to do here.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How do I convert text file to image for use with overlay

Post by fmw42 »

more control on caption than text

compare:

convert -size 250x250 -fill black -font Helvetica caption:@text.txt text.gif

which autosizes the font to fill the page (but you can specify the pointsize if you want and also gravity to adjust its position)

and

cat text.txt | convert -pointsize 24 -font Helvetica -fill black text:- text2.gif

which does not allow -size to be specified (ignores it if specified) and does not wrap if font too big. Image size is controlled by the -page media attribute and -density. Note cat text.txt is piped to convert where text:- (the minus means standard input) gets it that way.

Caption: can access the file more directly via @filename

text.txt is as follows in my test:


I am not trying to use IM to position. I will use good old fashioned
placement by the fixed font as is being done now when it prints currently. I
can supply samples if required but it should not make a difference. Just
take any text file of multiple lines and show me how to construct a command
which will convert that to a image using a fixed font of specified size and
I will be thrilled.



see http://www.imagemagick.org/Usage/text/#text and http://www.imagemagick.org/Usage/text/#caption and http://www.imagemagick.org/script/comma ... s.php#page

To be honest, I have not much experience with text: option but have used caption: more.
whenry

Re: How do I convert text file to image for use with overlay

Post by whenry »

Ok Thanks guys I am almost there. The biggest problem today is that i have been getting an image but it is a hex dump (you know the style hex block on the left with ASCII on the right). Turns out that i had control characters in the beginning of the file (this was designed to send to an HP printer) . When I removed them it ceased the weirdness.

Today's issues is more minor . i need to understand the available fonts and font sizes. I imagine I will be able to find those with some research.

By the way "TEXT:" is really what I need because I want it to interpret the line feeds from my test file as intended. caption does not do that (at least in it's default form) .
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How do I convert text file to image for use with overlay

Post by snibgo »

If the text file contains new lines, these are respected by "caption:". In Windows, new lines are CR-LF. In Unix, I assume just LF.
snibgo's IM pages: im.snibgo.com
whenry

Re: How do I convert text file to image for use with overlay

Post by whenry »

Ok now I know the available fonts (-list type) . I have to use a fixed width font since I need the data to line up with the column headings. That means I must choose courier. No problem but my line spacing is way way too much. As you can see here http://www.imgplace.com/viewimg215/744/45testimage.png . Is there a simple way to specify what i would call lines per inch if I was printing?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How do I convert text file to image for use with overlay

Post by snibgo »

I would start by stripping out some of the newlines from the input text file. It looks as if there is one blank line between every line of text, which you might not want. Then fiddle with "-pointsize".
snibgo's IM pages: im.snibgo.com
whenry

Re: How do I convert text file to image for use with overlay

Post by whenry »

Yeah I know it looks like that but here is the actuall text


Code: Select all

BATH COUNTY COMM HOSPITAL                 13142903
       ATTN:  DIETARY
       RT 220 NORTH                                                      PHONE #: 800-888-8018 and 615-537-3600
       HOT SPRINGS, VA 24445                                              DUNS #: 80-097-4735
       UNITED STATES OF AMERICA                                          FED ID#: 06-1523665

            BATH COUNTY COMM HOSPITAL                 13142904
            ATTN:  ACCOUNTS PAYABLE
            DRAWER Z                                                          ALADDIN TEMP-RITE LLC
            HOT SPRINGS, VA 24445                                             P.O. BOX 8500-3431
            UNITED STATES OF AMERICA                                          PHILADELPHIA, PA 19178-3431
                                                                              UNITED STATES OF AMERICA
Unless I am more confused than I think I am this has no 'extra' new lines
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How do I convert text file to image for use with overlay

Post by snibgo »

Please post the actual text file, and tell us the URL.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How do I convert text file to image for use with overlay

Post by fmw42 »

see kerning at http://www.imagemagick.org/script/comma ... hp#kerning

but I don't know if it works with text:
whenry

Re: How do I convert text file to image for use with overlay

Post by whenry »

Hmm not kerning since that is space between letters but "-interline-spacing" looks promising..... Damn !!

I am running an older version 6.0.7 and that option apparently does not exist

Double Damn. When I try to install 6.6 from the RPM I get numbers of dependencies errors and I am (as is clearly evidenced by my questions) very ignorant as to how to resolve such things..... sigh .....


Wendell
Post Reply