Gossamer Forum
Home : General : Perl Programming :

convert text to image

Quote Reply
convert text to image
Is there any module to do that? I want to read a plain text file and convert the content to image(gif/png/jpg...), just like a screenshot.

I downloaded Image::Magick but quite cunfused with its doc...
Quote Reply
Re: [sh2sg] convert text to image In reply to
Image Magick is the best way I know of. You need to go here:

http://www.imagemagick.org/
Quote Reply
Re: [Paul] convert text to image In reply to
yes i know image::magick and tried already, but can't get it work...
Quote Reply
Re: [sh2sg] convert text to image In reply to
We'll need a little more info :)
Quote Reply
Re: [Paul] convert text to image In reply to
maybe i misunderstand the way to create a new image from text, i use

use Image::Magick;
my $image = Image::Magick->new;
my $text = 'Hello World!';
$image->Annotate(font=>'arial.ttf', text=>$text);
$image->Write("test.gif");
undef $image;

arial.ttf is copied from windows font directory.

the above code is almost taken from image::magick's doc, but it doesn't work, nothing created and no error.

i tried other functions of image::magick, they work just fine.
Quote Reply
Re: [sh2sg] convert text to image In reply to
Maybe the following additions may help

Code:
use Image::Magick;
my $image = Image::Magick->new;
my $text = 'Hello World!';

$image->Set( size => "100x100" );
$image->ReadImage( "xc:white" );


$image->Annotate(font=>'arial.ttf', text=>$text);
$image->Write("test.gif");
undef $image;
Quote Reply
Re: [Aki] convert text to image In reply to
thanks AKi, and with this:

$image->Annotate(font=>'arial.ttf', text=>$text, fill=>'green', x =>10, y =>30);

it works :)

a small suggestion for gforum, make attachment embed (only JPG, GIF and PNG images) so it can display within the post.

Last edited by:

sh2sg: Nov 14, 2002, 7:33 PM
Quote Reply
Re: [sh2sg] convert text to image In reply to
Quote:
a small suggestion for gforum, make attachment embed (only JPG, GIF and PNG images) so it can display within the post.

You mean like this:



Tongue

Last edited by:

Paul: Nov 15, 2002, 2:09 AM
Quote Reply
Re: [Paul] convert text to image In reply to
Or like this:



Ivan
-----
Iyengar Yoga Resources / GT Plugins

Last edited by:

yogi: Nov 15, 2002, 3:22 AM
Quote Reply
Re: [yogi] convert text to image In reply to


yes i know i can edit my post, copy the url and use img markup tag... but why not make an option for attachment?
Quote Reply
Re: [yogi] convert text to image In reply to
I'm just having a play with Image::Magick (got into it after having to get image sizes with it). I currently have;

Code:
sub test {

print $IN->header();
use Image::Magick;

my ($text,$filename,$image,$image2);

use Image::Magick;
my $image = Image::Magick->new;
my $text = 'Hello World!';
$image->Set( size => "100x100" );
$image->ReadImage( "xc:white" );
$image->Set('pixel[49,49]'=>'red');
$image->Annotate(font=>'arial.ttf', text=>$text);
$image->Display(); #Write("test.gif");

print "done";
}

However, this is just printing a blank screen (and not even the 'done' message). Does anyone else know about this kinda stuff? All I have managed to do in Image::Magick before has been really basic. Now all I wanna do is generate an image, and show it Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] convert text to image In reply to
Quote:
got into it after having to get image sizes with it

That was overkill :) ...should have used Image::Size

Regarding your code trying adding:

print

..before each method call, eg..

print $image->ReadImage( "xc:white" );

...it should then display any errors.

This is working code I use on perlwhirl.com, try this...

Code:
use Image::Magick;

my $image = Image::Magick->new();
print $image->Set( size => "100x50");
print $image->ReadImage('xc:white');
print $image->Colorize( fill => 'red' );
print $image->Border( width => 5, height => 5, fill => 'blue' );
print $image->Raise( width => 5, height => 5, raise => 'True' );
print $image->Wave( amplitude => 5, wavelength => 30 );
print $image->Swirl( degrees => 300 );

print "Content-type: image/gif\n\n";
binmode STDOUT;
print $image->Write('gif:-');
Quote Reply
Re: [Paul] convert text to image In reply to
Mmm...thanks for the code, but it gives me an error;

Exception 435: Unable to open file (colors.mgk) [No such file or directory]

Is this an Image::Magick configuration error?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] convert text to image In reply to
Yup, you are missing files, or they are in the wrong place.
Quote Reply
Re: [Paul] convert text to image In reply to
BTW...what is perlwhirl? It gives me a password prompt when you try and visit it Tongue

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] convert text to image In reply to
Yep it's to keep prying eyes out =)
Quote Reply
Re: [Andy] convert text to image In reply to
Perl Whirl is the name for the Geek Cruises => http://www.geekcruises.com/

- wil
Quote Reply
Re: [Paul] convert text to image In reply to
Well, I have most of it working now. Unfortunatly Annotate is not working still (server config problem). I've been reading through the documentation at imagemagick.com, but can't seem to find any references of what the following grid references mean in a 'Draw' call;

Code:
points=>'20,20 40,40'

The whole statement is;

Code:
print $image->Draw(stroke=>'red', primitive=>'rectangle', points=>'20,20 40,40');

I've been playing with them, trying to work out if its the first or second part that defines the size, and also work out what the 'x' and 'y' reference part is.

Anyone got any ideas/experiences with this? Unsure

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Wil] convert text to image In reply to
Got it working now Smile

Code:
$image->Annotate(
text => $string,
stroke =>"red",
fill =>"blue",
x =>50,
y =>35,
pointsize=>14,
font =>"Arial");

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] convert text to image In reply to
Dear Andy, I have attached " magick.pdf " which is the best reference for Image Magick

I have found so far. I found this on the net via google, I did not write this.

It is 1.08 MB , so right click and save as.

Thanks

cornball
PS I think it may be a 4.0 version of Acrobat [ 3.0 fails to read with errors ] , 5.1 reads the file fine on WinXp

Last edited by:

cornball: May 23, 2003, 10:02 PM
Quote Reply
Re: [cornball] convert text to image In reply to
Thanks cornball, much appreciated Smile

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!