This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Converting text strings to gif files

Help for those learning Tcl or writing their own scripts.
Post Reply
d
dj-zath
Op
Posts: 134
Joined: Sat Nov 15, 2008 6:49 am
Contact:

Converting text strings to gif files

Post by dj-zath »

Hi everyone, Speechles and nml!

is this possable in TCL?

I want to take text strings (via varables) and convert them to simple gif files- nothing fancy, just "black text on an invisable background".

I heard you can do this in php.. though I couldn't find anything that showed HOW...

perhaps someone out there can offer some guidence and/or help?

(script examples would be greatly-appreciated!)

-DjZ-
:) :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Possible; yes, though far from trivial. I'd recommend you rely on some external application to generate the image instead. Could probably use php along with the GD library for that, or the netpbm software package (if available).
NML_375
d
dj-zath
Op
Posts: 134
Joined: Sat Nov 15, 2008 6:49 am
Contact:

Post by dj-zath »

thanks nml..

using a call to an external app won't be too much of an issue.. as long as it can be done CLI and unattended... (say, the bot calls it up and passes the string/varable data over)

the reason is because without it I'll have to use I-FRAMES.. and we know how pratical I-frames are these days??? NOT!!

so, I thought maybe I can convert the strings to gif files.. those I can pass directly out of the webserver...

-DjZ-
:) :)
User avatar
user
 
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

If you really want to generate images, try ImageMagick via TclMagick...

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

...but I don't see why that would be any easier than passing the data to the client some other way (javascript/remote server side include/rpc/whatever)
Have you ever read "The Manual"?
d
dj-zath
Op
Posts: 134
Joined: Sat Nov 15, 2008 6:49 am
Contact:

Post by dj-zath »

Hi there User! and thanks for your reply..

The main reason is that I can not pass or export said info to places like myspace or facebook!

These places do NOT allow any kind of scripting- EXPECIALLY javascript!

I have used rewrite rules to get php through.. but thats about the extent of my knowledge. :)

I got images through.. but I can't get TEXT through without either using an I-frame (not allowed) or to turn it into a link.. when, again, they'll allow a link, but it disrupts the flow of things since they make you click (and reclick) "validation" pages (and they say things like this link WILL give you a virus etc etc)

So, mainly its to get around their "bitch screens" and all that..

also, I have used TCL to generate php that will call common elements in places that are referenced to one-another, based on multiple varables all sharing the same image(s) and data..

This way, for example, "status lights" will all contain one or two gif files instead of (re)downloading the same gif file(s) multiple times on a given viewed page. its done for efficiency. :)

User: thanks for the link.. I'll have a look once I finish this post.

-DjZ-
:) :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

I guess the point assumed by both user and me, is that you were to generate the image locally, and then transfer it to your myspace/facebook/whatever using whatever means available... Not transfer a generated php-script or such...

Php can be run in command line mode, and is able to pass arguments on to the running application. All facilities (perhaps except the apache-extensions) are available in this mode, although $_POST, $_SERVER, and the other predefined superglobals would not have any meaning unless used as a httpd CGI application. As such, it's a very potent environment, and can handle most of your tasks.

The netpbm is a software package of several hundred tiny binaries that perform one single task on a specific image file. It uses a special image format(s) (called netpbm), and comes with a multitude of converters for most known image types. It also includes a library with the rudimentary functions needed for working with the netpbm format(s).

ImageMagick is a similar software package, and with the addition of TclMagick, you get a bridge between tcl and ImageMagick that'll allow you to interact with ImageMagick without using the exec command (although you are still invoking child processes to do the work).

All of the above mentioned three can rather easily create a new image with a content by your instructions, to be saved on the local filesystem. PHP has the additional feature of being able to run additional code, such as generating the image in memory and then FTP it to a remote location instead of saving it on the local filesystem. The netpbm and IM packages are generally known to render better-looking images than the GD library used by PHP, especially with image transforms such as resize. Which one to use, I suppose all comes down to what's available on the local system, and the needs of the application...
NML_375
d
dj-zath
Op
Posts: 134
Joined: Sat Nov 15, 2008 6:49 am
Contact:

Post by dj-zath »

Nml:

hi there buddy!

as I look at all this, I might just give it up altogether.. I thought it would be something simple to do.. mind you, theres a lot of fancy-smancy stuff one can do with graphics, however, I just needed something simple- "take plain text and convert it to a simple gif using a standard font on an invisable (or white space) background" but it seems that the overhead to do this is daunting!

I read somewhere that I could exec php and have this done lickity-split with next to no overhead and, being I allready have PHP installed (shell and apache) I thought it could be something I can call up.. and be done with it..

that doesn't seem to be the case, though, since I have to purchase and then install font libs and format libs and then conversion libs and then text libs.. etc etc etc...

it was just an idea.. scratched!

-DjZ-
:) :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Actually, that's pretty much what I've said all along... it really is that simple..
Why I'm saying far from trivial, is that you either need a php-environment or make sure external softwares such as netpbm or ImageMagick is installed. Once that's fulfilled, you need to know how to use these tools (thus we're really not talking of native tcl anymore).
I generally try not to assume that the ones reading my posts have a perfect knowledge in 20+ different languages, libraries, software packages, etc... Here on egghelp, I do assume some basic knowledge in tcl scripting, or the interrest of gaining such knowledge using various available resources.

Unfortunately, in your posts you start rambling about IFrames, mod_rewrite rules, etc, making me very confused at which location you want the image created, what resources are available there, and so on.
To avoid confusion, keep your posts simple and descriptive. Whether your myspace-page allows javascript or not is really of no interrest at all...

To use php to generate an image, just do something like this:

Code: Select all

catch {exec php -f ./generateImage.php -- $text} result
This would save any output from the generateImage.php script into the variable result. Whether you then want your php-script to output the image data, or write the image to disk, or ftp it to some offsite location is entirely up to you.

Edit: dropped the list command that managed to sneak in there.
Last edited by nml375 on Wed Dec 09, 2009 11:01 am, edited 1 time in total.
NML_375
d
dj-zath
Op
Posts: 134
Joined: Sat Nov 15, 2008 6:49 am
Contact:

Post by dj-zath »

Hi nml!

first off, I apologize if I confused anyone.. I was merely trying to give as much detail as I thought nessessary.

second, I have "bits and pieces" as far as knowledge goes.. an odd combanation.. (but thats beyond the scope of this post.)

In the end, all I needed is to drop the output Song.gif to the webserver which is merely a couple dir's away (all on the same machine) once there, then Apache takes care of all the rest.. I just needed a way to turn a string in TCL such as:

Code: Select all

set $Song "Take on Me - A-Ha";
then have $Song turned into Song.gif... really, that simple!

I'll try your suggestion and see what happens.. thanks for the help and we'll see what comes of this..

-DjZ
:) :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

Assuming the GD-library and php-module is available, the following php-script should do the trick:

Code: Select all

<?php
$im = imagecreate(200, 20);
$bg = imagecolorallocate($im, 255, 255, 255);
$text = imagecolorallocate($im, 0, 0, 0);
imagefill($im, 0, 0, $bg);
imagestring($im, 5, 0, 0, $argv[0], $text);
imagegif($im, "song.gif");
?>
I havn't verified the code, as I don't use the GD library myself, but should work to my best knowledge.
Usage:

Code: Select all

php image.php -- "Here we go again - Whitesnake"
NML_375
Post Reply