View Full Version : Adding Text to Image - Resizing Text etc... (Image Chef)

08-13-2008, 09:41 PM
I'm trying to make an Image-Chef like PHP function. Currently I have this


header("Content-type: image/png");
$string = $_GET['text'];
$im = imagecreatefrompng("Egypt.png");
$orange = imagecolorallocate($im, 219, 181, 1);
$black = imagecolorallocate($im, 0, 0, 0);
$px = (imagesx($im) + 16 * strlen($string)) / 2;
imagestring($im, 26, $px, 48, $string, $black);
imagestring($im, 25, $px, 47, $string, $orange);


This allows the production of an image with the text I input in the Url (in fore color and with a shadow) lying over the base image provided. The intention is just a small thing similar to imagechef.com where I can enter small amounts of text and incorporate it directly onto the image. The thing I am struggling with primarily is resizing the text based on the length of the string.

Basically, on image chef, there is a defined width that the text can occupy. If the text occupies more that this width it is scrunched together to fit. Is it possible to do this here? Any suggestions on improvement?


08-19-2008, 07:49 PM
Anyone have any ideas?