LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 12-13-2014, 05:38 PM   #1
keirvt
Member
 
Registered: Sep 2006
Location: Sydney Australia
Distribution: fedora/Ubuntu
Posts: 156

Rep: Reputation: 18
Imagemagick text to image


I want to convert a page of text, columns and rows of numbers and labels, to an image. Then overlay the image on a background of logos lines and stuff.

Everything works almost!

The problem is the Imagemagic text to image command

convert filein.txt fileout.png

Doesn't properly preserve spaces which squashes into less than a character width and therefore the columns don't line up.

I have tried specifying a font, for example

convert filein -font DejaVu-Sans-Mono-Book fileout.png

but no apparent change in whitespace packing.

Any suggestions please
 
Old 12-13-2014, 07:12 PM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,627

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
you might have better results uning
"asciitopgm" or "pstopnm"

should be installed by default as part of "netpbm"

and converting a text file to postscript should be no problem
 
Old 12-14-2014, 02:32 AM   #3
keirvt
Member
 
Registered: Sep 2006
Location: Sydney Australia
Distribution: fedora/Ubuntu
Posts: 156

Original Poster
Rep: Reputation: 18
Solved

asciitopgm just rendered dollops on the page. Completely unreadable.

Rendering postscript from the text and then to jpg nearly worked.

However, there is always some point in the conversion chain that spoils the final outcome. the first test to postscript conversion is hampered by limitations of the media. So in my case text lines would extend beyond the page edge and wrap to the next line. Changing media to A2 fits the lines on okay although the page size has varying effects on subsequent conversion to jpg or tiff.
Most final results using the scripts suggested or even the convert command were poor.

In the end Imagemagick is the tool!
Imagemagic's "convert" can draw text into an image. It has the feature to draw multi line text from a file An example of its use is

Code:
convert -font DejaVu-Sans-Mono-Bold -pointsize 14 -gravity northwest label:@infile.txt outfile.jpg
There is some playing around required to find a font that doesn't squash whitespace but you can control font and poinsize and the rendered image adjusts to line length.
Cool!

Last edited by keirvt; 12-14-2014 at 02:33 AM.
 
Old 02-23-2015, 08:35 PM   #4
fhleung
Member
 
Registered: Aug 2004
Distribution: Lubuntu Live OS
Posts: 432

Rep: Reputation: 30
so the command would be, let me try

Code:
convert -font DejaVu-Sans-Mono-Bold -pointsize 14 -gravity northwest label:@infile.txt outfile.jpg
 
  


Reply

Tags
convert, imagemagick


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
getting image size (imagemagick) btb Linux - General 6 10-15-2013 02:39 PM
LXer: How to create a simple text image with Imagemagick LXer Syndicated Linux News 0 09-02-2012 08:51 AM
Video 2 Image - ImageMagick For Videos ??? freebies Linux - Software 1 03-28-2005 03:17 PM
Resize Image using ImageMagick mddolloff Linux - Software 1 11-20-2004 05:07 PM
Centering text on an image using ImageMagick barisdemiray Linux - Software 2 09-20-2004 11:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration