Page 1 of 1

simple conversion of text report to jpg image file

Posted: 2019-07-22T19:23:56-07:00
by davemagi
Greetings fellow imagers

I am new to imagemagick and I have what seems to me a very simple straight forward task to perform. I have developed software that produces a text file containing data in rows and column format, separated by the [ and ] characters. I cannot send this to a website as a text file. It can only be sent as an image file like jpg. Usually this file takes about half standard printer page but can vary. Imagemagick simply has too many options and parameters for me to make any headway with this conversion. My latest error message for the command line "magick convert fxDtable.txt
fxDtable.jpg" reads;

convert: improper image header 'fxDtable.txt' @ error/txt.c/ReadTXTImage/443.
convert: no images defined 'fxDtable.jpg @ error/convert.c/ConvertImageCommand/3273.

what do I have to add to get this to work ? is it size, draw .... ? There are some entries in the forum about text to image conversion but they have not helped me make sense of this.

Thank You

Re: simple conversion of text report to jpg image file

Posted: 2019-07-22T19:36:56-07:00
by fmw42

Re: simple conversion of text report to jpg image file

Posted: 2019-07-23T03:11:00-07:00
by snibgo
I suppose you want to rasterize the characters in the text file. The meaning of those characters is not relevant.

Prefix the input test filename with "TEXT:". See http://www.imagemagick.org/Usage/text/#text . For example:

Code: Select all

magick TEXT:fxDtable.txt fxDtable.jpg
Does that do what you want?

Re: simple conversion of text report to jpg image file

Posted: 2019-07-23T11:42:49-07:00
by davemagi
Thank you for your timely advice. The conversion takes place, but now I see I have another problem. In text, the rows and columns come out perfectly aligned on top of each other. Now the spacing is skewed so the columns do not align properly. Is there any remedy for this ?

Re: simple conversion of text report to jpg image file

Posted: 2019-07-23T11:45:51-07:00
by fmw42
Please post your input and output files to some free hosting service and put the URLs here so we can see what you are doing. Also identify your exact Imagemagick version and platform/OS.

Re: simple conversion of text report to jpg image file

Posted: 2019-07-23T12:36:10-07:00
by snibgo
davemagi wrote:In text, the rows and columns come out perfectly aligned on top of each other. Now the spacing is skewed so the columns do not align properly. Is there any remedy for this ?
Did you read the link I posted?
I purposely used the 'fixed-width' font 'CourierNew' in the above so as to preserve the character spaced formatting that is present in the printed page.

Re: simple conversion of text report to jpg image file

Posted: 2019-07-24T08:34:44-07:00
by davemagi
I am using version 7.0.8-Q16 on a Windows 8.1 system

Sorry I missed that point about the CourierNew. I retried the command line with the font specified (-font CourierNew text:input output)but now it tells me;

unable to read font 'CourierNew' @ warning/annotate.c/RenderType/953

The other parameters specified in the link example i.e. | col -b | expand | \ were not clear to me as to the necessity of using them. As to not finding the font, outside of adding the ImageMagick directory to the Path, I have not changed anything. I could also use the output as a pdf file if this would make anything easier and more comprehensible. I tried doing it and although a pdf file was produced, the Adobe reader claimed the file was damaged and could not be read.

The following is a partial sample of the text file to be converted although it did not come out aligned in the copy command. Basically every [ and ] character in my report is aligned above and below each other in the order they appear in the line.

[ GJ ] EU ] GU ] AU ] AJ ] GN ] EJ ] CJ ] EA ] GA ] NU ] NJ ] EN ] UJ ] UC ] EC ] EG ] UCh] GCh] GC ] AN ] AC ]

Trend: [BAll]Bl52]HML ]Bl52]Bl52]HML ]Bl52]Ab20]AAll]A200]Bl52]Bl52]LMH ]Bl52]Ab50]Bl52]LMH ]Ab50]HML ]HML ]Ab50]HML ]
MAOrd: [5202]2052]5202]2052]2052]2520]2052]2052]2205]2520]2052]2052]2025]2052]2520]2052]2025]2520]5220]5220]2025]2052]
Cndle: [ ]SpTp]LgUS]SpTp]SpTp] ]C>YH]C>YH]SpTp] ]C<YL]SpTp]C>YH]C>YH]C<YL]C<YL]LgLS] ]LgUS]C<YL]SpTp]C<YL]
Cndle2: [ ]DbPB] ]DbPB]DbPB] ] ] ]DbPB] ] ]DbPB] ] ] ] ] ] ] ] ] ] ]

Thank You again for all assistance rendered

Re: simple conversion of text report to jpg image file

Posted: 2019-07-24T08:44:00-07:00
by snibgo
"magick -list font" will list available fonts. On my Windows 8.1 machine, the font is called "Courier-New".

Code: Select all

magick -font Courier-New TEXT:in.txt out.png

Re: simple conversion of text report to jpg image file

Posted: 2019-07-24T09:32:59-07:00
by fmw42
If your type.xml file does not include a font, then you will either need to edit the type.xml file or use the path to the font file rather than just its name.