Generate images on the fly

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
waradmin
Forum Contributor
Posts: 240
Joined: Fri Nov 04, 2005 2:57 pm

Generate images on the fly

Post by waradmin »

Ive seen this done before, even had a script at one time but lost it, so ill ask it here (i did search and found nothing). I want to generate images with custom text on them. So for example image.php?size=2&text=sweet or whatever.

For people who know a lot about php that probably isnt that hard. But i also (if possible) want it to look something like the header on my blog (http://www.open-server.org). I dont know if that is possible or not but i would like anyones help who can offer ideas. I have the font downloaded for the banner on my site, and i would like to be able to automaticly generate the text on it on the fly for the blog hosting service i run that way people can have custom banner images.

Thanks in advance.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

study and play around with the gd functions..
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

User avatar
phpdevuk
Forum Contributor
Posts: 220
Joined: Mon Jul 04, 2005 5:31 am
Location: UK
Contact:

Post by phpdevuk »

this sounds like the sort of thing your after http://www.alistapart.com/articles/dynatext/
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Code: Select all

<?php

$size = (isset($_GET['size']) ? intval($_GET['size']) : ''); /* change '' to default size */
$text = (isset($_GET['text']) ? strval($_GET['text']) : ''); /* change '' to default text */

$image = imagecreate(300, 300); /* create image 300pix by 300pix */
$background = imagecolorallocate($image, 255, 255, 255); /* white background */
$textcolour = imagecolorallocate($image, 0, 0, 0); /* black text */

imagestring($image, $size, 0, 0, $text, $textcolour);

header('Content-Type: image/png');
imagepng($image);
imagedestroy($image);

?>
off the top of my head :)
User avatar
waradmin
Forum Contributor
Posts: 240
Joined: Fri Nov 04, 2005 2:57 pm

Post by waradmin »

The easiest one is Jenks. How would i use custom fonts with that, and colors. Or is that not possible. Thanks.
Post Reply