note 37523 added to function.imagecreatetruecolor

From: Date: Tue, 18 Nov 2003 19:40:37 +0000
Subject: note 37523 added to function.imagecreatetruecolor
Groups: php.notes 
Request: Send a blank email to php-notes+get-60583@lists.php.net to get a copy of this message
Unfortunately the @imagecreatetruecolor() method doesn't even work because php dies with a fatal error noting that GD 2 is required. You can't even capture this error with a custom error handler. I have come up with a function to get the GD version number that seems to work pretty well on every version of PHP and GD I've thrown at it (even CLI versions.) It's obviously not the most efficient thing in the world, but it does cache the result in a static variable so calling it multiple times doesn't slow down further. function gd_version() { static $gd_version_number = null; if ($gd_version_number === null) { // Use output buffering to get results from phpinfo() // without disturbing the page we're in. Output // buffering is "stackable" so we don't even have to // worry about previous or encompassing buffering. ob_start(); phpinfo(8); $module_info = ob_get_contents(); ob_end_clean(); if (preg_match("/\bgd\s+version\b[^\d\n\r]+?([\d\.]+)/i", $module_info,$matches)) { $gd_version_number = $matches[1]; } else { $gd_version_number = 0; } } return $gd_version_number; } Then you can simply use it something like this: if (gd_version() > 2) { $image = ImageCreateTrueColor($width, $height); } else { $image = ImageCreate($width, $height); } ---- Manual Page -- http://www.php.net/manual/en/function.imagecreatetruecolor.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37523 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37523&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37523&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#60583) next »