AshMan Posted February 5, 2003 Share Posted February 5, 2003 Does anyone know how I can get PHP or JSP to create JPEGs from some text? I want to input a string $myString="Hello Worlds"; for example and get that to generate an image that looks like the one attached. Thanks. Link to comment Share on other sites More sharing options...
0 Ricky Baby Posted February 5, 2003 Share Posted February 5, 2003 there is a better way than this but the way ive done it with my sig is $image=imageCreateFromPNG("123.png"); imageString($image,5,10,10,$mystring,000000); imagePNG($image); imageDestroy($image); that will create a image from 123.png and put the text on it Link to comment Share on other sites More sharing options...
0 AshMan Posted February 5, 2003 Author Share Posted February 5, 2003 Can you post all the code to do this? I'm kinda new at this stuff. Link to comment Share on other sites More sharing options...
0 spike232 Posted February 5, 2003 Share Posted February 5, 2003 <? Header("Content-Type: image/jpeg"); //Image header //Gets text, and converts spaces $string=implode($argv," "); $string = str_replace("%20", " ", $string); $string = str_replace("_", " ", $string); $myimage = ImageCreateFromJpeg("baseimage.jpg"); //Base image $black = ImageColorAllocate($myimage, 0, 0, 0); //colour (rgb last 3 numbers) $fontsize = 5; ?//1 - 5 font size $xcoord = 25; ?//X-coordinate $ycoord = 150; ?//Y-coordinate, both from top left cornor ImageString($myimage, $fontsize , $width, $height, $string, $black); //writes text ImageJpeg($myimage); //creates image ImageDestroy($myimage); ?> save that in a php file, nothing else and there must be no spaces or anything out side the <? ?> bits then to call it u can use in html: <img src="filename.php?Hello World" border="0"> if udont want to input the string from the link u can set it in the page, u can use either jpeg or png just change hat bit of all the commands, gif is no longer suport:( :( if u dont want to use a base image then u can create one from scatch but im not sure how Link to comment Share on other sites More sharing options...
0 AshMan Posted February 5, 2003 Author Share Posted February 5, 2003 (edited) Great stuff! Thanks. There are 3 more questions that I am hoping you can help me with on this issue: 1) Can the image now be saved? I mean, I want it to automatically same the image in some directory for me. 2) How can I add a carriage return in the text? I've tried using the * character and replacing it with a "\n ". Here the code I used: $string = str_replace("*", "\n", $string); And here's the input string: Hello*Worlds But it didn't put a carriage return in between the two words. Any thoughts on this? 3) Can I use this code in my JSP pages too? Thanks. Edited February 5, 2003 by AshMan Link to comment Share on other sites More sharing options...
0 ctrlaltdel Posted February 6, 2003 Share Posted February 6, 2003 I'm looking fo something similar to this, but i want it so that my users can have graphics made with the text they want using a base style (similar to flaming text) Is this possible? Link to comment Share on other sites More sharing options...
0 spike232 Posted February 6, 2003 Share Posted February 6, 2003 1) i have no idea, 2) i was tring to do the same thing all last night :p finally got it to work, but it depends on certin limits of the image, this is the code i used: <? Header("Content-Type: image/jpeg"); $maxlines = 8; $maxperline = 30; $string=implode($argv," "); $string = str_replace("%20", " ", $string); $string = str_replace("_", " ", $string); $string = wordwrap( $string, $maxperline ); $stringarr = explode("\n", $string); $lines = count($stringarr); $myimage = ImageCreateFromJpeg("baseimage.jpg"); $black = ImageColorAllocate($myimage, 0, 0, 0); $width = 25; if($lines > $maxlines) { $lines = $maxlines; } switch($lines) { case 1: $height = 180; break; case 2: $height = 175; break; case 3: $height = 165; break; case 4: $height = 160; break; case 5: $height = 155; break; case 6: $height = 150; break; case 7: $height = 140; break; case 8: $height = 135; break; } for ($i = 0; $i < $lines; $i++) { ImageString($myimage, 5, $width, $height, $stringarr[$i], $black); $height = $height + 15; } ImageJpeg($myimage); ImageDestroy($myimage); ?> on my image its like a comic with character and then text box, so this will fit the text nicly in it 3) the image is self contained in that file, so u can call it from anything and just pass the right paramaters and it should function like a normal image I'm looking fo something similar to this, but i want it so that my users can have graphics made with the text they want using a base style (similar to flaming text) i think that might be a little beyond what this can do, the rest of the craphics options are very simplistic, like drawing basic shapes and stuff :unsure: Link to comment Share on other sites More sharing options...
0 Tim Dorr Veteran Posted February 6, 2003 Veteran Share Posted February 6, 2003 I dunno about JSP. It's done in php through gd_image, which is now an included library with the package. It's separate in terms of development, but I don't know how much it will plug into java or other projects... Link to comment Share on other sites More sharing options...
0 nacs Posted February 6, 2003 Share Posted February 6, 2003 Lookup 'GD library' on google or php.net. You may also wish to check hotscripts.com for premade scripts and tutorials. Link to comment Share on other sites More sharing options...
0 mr_daemon Posted February 10, 2003 Share Posted February 10, 2003 I could contribute the source code to my signature if you want. Link to comment Share on other sites More sharing options...
0 AshMan Posted February 11, 2003 Author Share Posted February 11, 2003 I could contribute the source code to my signature if you want. Thank you, that would be very useful. Link to comment Share on other sites More sharing options...
0 BxBoy Posted February 11, 2003 Share Posted February 11, 2003 I've already posted the full source to my sig, maybe that can help you a bit.. (the link is below my sig). .. as for your 1) question, I'm trying to do that as well, I'm working on putting progressive level bars in my sig, but haven't figured it out yet. I'm thinking I would need to do a 2-pass thing: first generate the first image, save it, and then generate the image (with the graph) on top of that. Link to comment Share on other sites More sharing options...
Question
AshMan
Does anyone know how I can get PHP or JSP to create JPEGs from some text?
I want to input a string $myString="Hello Worlds"; for example and get that to generate an image that looks like the one attached.
Thanks.
Link to comment
Share on other sites
11 answers to this question
Recommended Posts