GD 1.8.3 & PNG Images - Speed

From: Date: Thu, 31 Aug 2000 14:49:46 +0000
Subject: GD 1.8.3 & PNG Images - Speed
Groups: php.general 
Request: Send a blank email to php-general+get-14603@lists.php.net to get a copy of this message
Hi, I'm using PHP 4.0.2 with GD 1.8.3/TTF support compiled in statically, and PHP statically in Apache 1.3.12, using the Zend Optimiser. I'm retreiving information from a MySQL database to create, from an original PNG template, a image (in this case buttons for a website) with TTF text overlaid, which I'm then using ImagePNG to output. My problem is it's taking approximately 4 seconds to read the PNG file in with ImageCreateFromPNG(). The rest of the script takes about 0.03 seconds to complete which is quite reasonable (it's on a Linux box of reasonably high specifications). It is definately ImageCreateFromPNG which is stalling the script. If I read in from a JPEG, using ImageCreateFromJPEG(), the script comes back down to taking a total of 0.04 secs to complete (much more reasonable :), but JPEGs are no good for non-photographic content, and it screws with the colouring. Anyone know of any speed issues with using ImageCreateFromPNG, or anything I can do to speed it up? Below is the code which I'm using: if (@mpf_db_num_rows($image_data)) { $image_data_values = mpf_db_fetch_array($image_data); $imagepath = DIR_BUTTONS . $image_data_values['sites_templates_id'] . '.png'; $im = imagecreatefrompng($imagepath); // here is where it takes 4 seconds. $tmpl_size = GetImageSize($imagepath); $color = ImageColorAt($im, 0, $tmpl_size[1] - 1); $size = ImageTTFBBox(12, 0, DIR_FONTS . $image_data_values['fonts_filename'], $image_data_values[@'sites_button' . $num]); $dx = abs($size[2]-$size[0]); $dy = abs($size[5]-$size[3]); $xpad = abs(($tmpl_size[0] - $dx)/2); // x-axis padding $ypad = abs(($tmpl_size[1] - $dy)/2); // y-axis padding ImageTTFText($im, 12, 0, (int)($xpad), $dy+(int)($ypad), -$color, DIR_FONTS . $image_data_values['fonts_filename'], $image_data_values[@'sites_button' . $num]); ImagePng($im); ImageDestroy($im); } Thanks very much :) Mark

« previous php.general (#14603) next »