Page 1 of 2
Spaces not aligning on lines using imageMagick
Posted: 2016-05-23T14:45:47-07:00
by gauravg
Hello,
I am using imagemagick 32 bit Version 7.0.1-3 on Windows 7. I am generating multiple reports in txt and then converting them to jpg using imagemagick. It is generating the image fine but the spacing between text is not aligning in JPG as it is in txt. Here below is the example.
Name Accessed Modified Lines
FIL IMAGE1 19-MAY-2016 19-MAY-2016 14
Please paste above in notepad file named anlist.txt and align the data such as Name and IMAGE1 start from same position. Accessed and 19-MAY-2016 starts from same position. Modified and 19-MAY-2016 starts from same position and for Lines 14 comes at "es" of Lines. Now when I use below command on imagemagick, I expect to see the exact same formatting where data aligns properly on jpg but it doesn't. The data doesn't align properly. There are NO TABS but only spaces.
Code: Select all
convert -quiet -font CourierNew anlist.txt -blur 0x0.7 -resample 72 -unsharp 0x0.7 -trim +repage -bordercolor white -border 3 anlist.jpg
Could you please suggest me, what option I need to use to have the correct formatting?
Re: Spaces not aligning on lines using imageMagick
Posted: 2016-05-23T14:57:28-07:00
by fmw42
Post your text file and your image to some free hosting service and put the URLs here so we can see what you get. Does the same happen if you only convert the text to jpg with no other processing? Did you use the same font when creating the text file as you specify in your command?
My guess is that tabs are treated like any other white space when converted to raster format.
I do not think you can specify a font when converting from text to raster unless you use one of the text to image constructs such as label: or caption:. See
http://www.imagemagick.org/Usage/text/
Re: Spaces not aligning on lines using imageMagick
Posted: 2016-05-23T14:59:22-07:00
by gauravg
Here are the images showing txt and JPG output. I just need them to look exact same (w.r.t formatting and alignment).
Also yes the same problem happen when I just use the convert txt to jpg without any other inputs.
http://imgur.com/a/3GMVm
Re: Spaces not aligning on lines using imageMagick
Posted: 2016-05-23T15:06:47-07:00
by fmw42
Sorry, but I cannot even get that. My tabs show up as ? when I do
convert text.txt text.jpg
Can you also post your text file, since your tabs do not show up in your post text above.
Re: Spaces not aligning on lines using imageMagick
Posted: 2016-05-23T15:10:19-07:00
by gauravg
I think the font doesn't matter for txt files as there are no different fonts available for notepad. You could try a simple test as below.
On 1st Line, please type OK Followed by Two Spaces and then HERE. Then on Second line 4 Spaces followed by TEST. So it would look something like
OK HERE
TEST
You would see it perfectly align in NOTEPAD. Also if you copy this text to Word and use font Courier New, there also it would align. But printing this using imagemagick in jpg or png or bmp would not have this alignment..
I am not able to upload txt on imgur, it is giving upload error. Could you please quickly create a txt file using above information? Thank you so much for looking into this..
Re: Spaces not aligning on lines using imageMagick
Posted: 2016-05-23T15:22:20-07:00
by fmw42
The two lines seem to be center aligned in the jpg. They only align if the text file uses a monospaced font. In the first case I used monaco and it did not align. In the second case I used courier (monospaced) and it aligns.
Try creating your text file in Wordpad using a monospaced font.
Re: Spaces not aligning on lines using imageMagick
Posted: 2016-05-23T15:26:50-07:00
by gauravg
When I am using Wordpad to create the file and save as txt it says all formatting would be lost and that is what is happening as well. Not able to generate the correct one.
Could you please provide me the changes, I need to do in the command I am using. I am not able to understand where you used the fonts. Also if possible please provide me the txt file you used, so that I could also try it on..
Thank you so much once again!
Re: Spaces not aligning on lines using imageMagick
Posted: 2016-05-23T15:30:21-07:00
by fmw42
I just opened a new text file in my text editor (on Mac), then I chose courier for the font and then I typed what you said above. Then I simply did
convert textfile.txt textfile.jpg
Do the same using Wordpad, where you can choose a font.
Re: Spaces not aligning on lines using imageMagick
Posted: 2016-05-23T15:40:14-07:00
by gauravg
I just tried this on Mac. TextEdit doesn't allow me to save the extension as txt. Also if I am copying txt file from Windows to Mac and opening in TextEdit, then it is not providing me options to change font etc.
Re: Spaces not aligning on lines using imageMagick
Posted: 2016-05-23T15:53:29-07:00
by fmw42
In TextEdit under FORMAT->FONTS->SHOW FONTS
Then under PREFERENCES->NEW DOCUMENT-> SET TO PLAIN TEXT rather than rich text.
This is on my Mac Snow Leopard. I am not sure what has changed since then relative to current releases of Mac OSX.
I would not recommend transferring a Windows file to the MAC. They have different line endings and that has caused me trouble.
I was using a different text editor on the Mac called BBEdit. There is a free version called TextWrangler. (barebones.comd)
I do not have windows, but I would expect that Wordpad (not Notepad) would work to allow you to pick a font and save as plain text (not .doc).
Re: Spaces not aligning on lines using imageMagick
Posted: 2016-05-23T16:05:15-07:00
by gauravg
Thanks Fred. I tried it on Windows and Wordpad allowed me to save as Plain Text but Results are same as before. It doesn't align.
There is a option called text:- in imagemagick that could do what I want to do but when I am using that, imagemagick is crashing on my windows.
Do we have any other option that could keep the spaces intact and not reduce it automatically?
Re: Spaces not aligning on lines using imageMagick
Posted: 2016-05-23T16:07:31-07:00
by fmw42
In Wordpad, did you select a monospace font such as courier? Try that on the Mac, if your Windows fails.
IM txt:- is not what you want. It converts raster images to show pixel locations and colors for every pixel in the image.
Re: Spaces not aligning on lines using imageMagick
Posted: 2016-05-23T16:14:20-07:00
by gauravg
Sure Fred. I would try that on Mac but I need it on Windows..
I was taking about text:- as opposed to txt:-
On the page here
http://www.imagemagick.org/Usage/text/
It is written that..
On the other hand, "text:" will handle just about any text file, without modifying the final image size produced, or word-wrapping very long lines. You also do not need to pre-process and special characters as you would if you used the text on the command line. Finally and more importantly if a fixed width font (like Courier) is used, files with spaced out columns of data, will still have that data in spaced out columns.
Basically "text:" will convert the input file 'AS IS'.
Re: Spaces not aligning on lines using imageMagick
Posted: 2016-05-23T16:19:50-07:00
by fmw42
Never used that option. But I just tried again. I created a text file using Monaco as the font. Then
convert -font monaco text.txt text.jpg
That worked.
So I tried the same with Helvetica and it almost aligned. Only slightly off.
Sorry, I do not know what to tell you. You should be able to select a monospaced font in Wordpad and save the file. Then try the above specifying the same monospaced file as the font. Note sure that is needed, but the monospaced font in the file is needed.
Re: Spaces not aligning on lines using imageMagick
Posted: 2016-05-23T16:30:02-07:00
by fmw42
This works for me:
Code: Select all
cat text.txt |\
convert -background lightblue -fill blue -pointsize 18 \
text:- -trim +repage -bordercolor lightblue -border 3 \
text_trimmed2.gif
Sorry I do not know if Windows allows cat. But you can probably do print or echo.