Re: GD - dynamic PNG generation

From: Date: Thu, 27 Mar 2003 22:32:56 +0000
Subject: Re: GD - dynamic PNG generation
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-141323@lists.php.net to get a copy of this message
Conor McTernan wrote:
Coding wise, I currently read the text in from a file, then put the text into an array, each line being a seperate entry in the array. I then create a PNG image approx 490*1848(i change the image size depending on the amount of text). I dont do anything really strange in my image function, apart from performing a wordwrap on the text before i start displaying it, just to make the image readable.
I'm trying to do allmost exactly the same, but I can't get the wordwrap to work in the png creation, (wordwrap part of the code works on ordinary html creation)the code i wrote is: header ("Content-type: image/png"); $fp = fopen('randquote.txt', r);
        while (++$i and $line = fgets($fp, 4096)) {
            if ((mt_rand() / mt_getrandmax() * $i) < 1) { $it = $line; }
        }
        fclose($fp);
$txt = wordwrap($it, 20, "\r\n", 1); $im = @imagecreate (468, 100) or die ("Cannot Initialize new GD image stream"); $bg = ImageColorAllocate($im,255,255,255); $tx = ImageColorAllocate($im,0,0,0); ImageFilledRectangle($im,0,0,200,200,$bg); $trans=imagecolortransparent($im,$bg); ImageString($im,3,10,10,"$txt\r\n",$tx); // send the image ImagePng($im); to see the output of the script: http://magikern.sytes.net/code/php/gd_png_dynamic/image_rand_quote.html

« previous php.general (#141323) next »