RE: [PEAR] image_transform errors with GD2
| From: | ThE PhP_KiD | Date: | Mon, 21 Apr 2003 18:52:18 +0000 |
| Subject: | RE: [PEAR] image_transform errors with GD2 | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-4981@lists.php.net to get a copy of this message | ||
HI !
I've found a better solution in order
to get what version GD are PHP running.
Instead to use on our scripts "SetGD2()"
to indicates if we are runinng GD2, we must
to create the constuctor (are not created),
on file "image/transform/driver/GD2.php".
To get what version GD are running, we need
"gd_info()", which works only on PHP 4.3 or higher.
If we don't have PHP4.3, we can simulate gd_info()
with phpinfo()
I pick the original gd_info() "emulator" from user's
apport from manual "php.net".
If you want all fixes on a simple file, send me a email.
Thank you.
Mac
---------------------------------------------------------------
function Image_Transform_Driver_GD() {
$code = 'function gd_info() {
$array = Array(
"GD Version" => "",
"FreeType Support" => 0,
"FreeType Support" => 0,
"FreeType Linkage" => "",
"T1Lib Support" => 0,
"GIF Read Support" => 0,
"GIF Create Support" => 0,
"JPG Support" => 0,
"PNG Support" => 0,
"WBMP Support" => 0,
"XBM Support" => 0
);
$gif_support = 0;
ob_start();
eval("phpinfo();");
$info = ob_get_contents();
ob_end_clean();
foreach(explode("\n", $info) as $line) {
if(strpos($line, "GD Version")!==false)
$array["GD Version"] = trim(str_replace("GD Version", "",
strip_tags($line)));
if(strpos($line, "FreeType Support")!==false)
$array["FreeType Support"] = trim(str_replace("FreeType Support",
"", strip_tags($line)));
if(strpos($line, "FreeType Linkage")!==false)
$array["FreeType Linkage"] = trim(str_replace("FreeType Linkage",
"", strip_tags($line)));
if(strpos($line, "T1Lib Support")!==false)
$array["T1Lib Support"] = trim(str_replace("T1Lib Support", "",
strip_tags($line)));
if(strpos($line, "GIF Read Support")!==false)
$array["GIF Read Support"] = trim(str_replace("GIF Read Support",
"", strip_tags($line)));
if(strpos($line, "GIF Create Support")!==false)
$array["GIF Create Support"] = trim(str_replace("GIF Create Support",
"", strip_tags($line)));
if(strpos($line, "GIF Support")!==false)
$gif_support = trim(str_replace("GIF Support", "", strip_tags($line)));
if(strpos($line, "JPG Support")!==false)
$array["JPG Support"] = trim(str_replace("JPG Support", "",
strip_tags($line)));
if(strpos($line, "PNG Support")!==false)
$array["PNG Support"] = trim(str_replace("PNG Support", "",
strip_tags($line)));
if(strpos($line, "WBMP Support")!==false)
$array["WBMP Support"] = trim(str_replace("WBMP Support", "",
strip_tags($line)));
if(strpos($line, "XBM Support")!==false)
$array["XBM Support"] = trim(str_replace("XBM Support", "",
strip_tags($line)));
}
if($gif_support==="enabled") {
$array["GIF Read Support"] = 1;
$array["GIF Create Support"] = 1;
}
if($array["FreeType Support"]==="enabled"){
$array["FreeType Support"] = 1; }
if($array["T1Lib Support"]==="enabled")
$array["T1Lib Support"] = 1;
if($array["GIF Read Support"]==="enabled"){
$array["GIF Read Support"] = 1; }
if($array["GIF Create Support"]==="enabled")
$array["GIF Create Support"] = 1;
if($array["JPG Support"]==="enabled")
$array["JPG Support"] = 1;
if($array["PNG Support"]==="enabled")
$array["PNG Support"] = 1;
if($array["WBMP Support"]==="enabled")
$array["WBMP Support"] = 1;
if($array["XBM Support"]==="enabled")
$array["XBM Support"] = 1;
return $array;
}';
if(!function_exists("gd_info")) eval($code);
$info_gd=gd_info();
if(strpos("x".$info_gd['GD Version'],'2.')) {
$this->GD2=true;
} else {
$this->GD2=false;
}
}
------------------------------------------------------
and :
------------------------------------------------------
Class Image_Transform_Driver_GD extends Image_Transform
{
// .... some vars
var $GD2 = false;
..
}
///////
function _resize($new_x, $new_y) {
if ($this->resized === true) {
return PEAR::raiseError('You have already resized the image
without saving it.
Your previous resizing will be overwritten',
null, PEAR_ERROR_TRIGGER, E_USER_NOTICE);
}
if($this->GD2){ /// <--- This is line I've changed
// echo "working with GD2!";
$new_img =ImageCreateTrueColor($new_x,$new_y);
} else {
// echo "working with GD1!";
$new_img =ImageCreate($new_x,$new_y);
}
if($this->GD2){ /// <--- This is another line I've changed
// echo "working with GD2!";
ImageCopyResampled($new_img, $this->imageHandle, 0, 0, 0, 0,
$new_x, $new_y, $this->img_x, $this->img_y);
} else {
// echo "working with GD1!";
ImageCopyResized($new_img, $this->imageHandle, 0, 0, 0, 0,
$new_x, $new_y, $this->img_x, $this->img_y);
}
$this->old_image = $this->imageHandle;
$this->imageHandle = $new_img;
$this->resized = true;
$this->new_x = $new_x;
$this->new_y = $new_y;
return true;
}