【发布时间】:2011-10-27 04:11:26
【问题描述】:
好的,所以我在谷歌搜索和阅读 cmets 后更改了我的代码。
但是现在得到这个错误
警告:imagecopyresampled():提供的参数不是有效的图像资源 /home/realcas/public_html/eshop/ecms/system/classes/photofetch.php 上 第 51 行 ‰PNG IHDRâI¯©m 警告:imagepng() [function.imagepng]: gd-png:致命的 libpng 错误:zlib 错误 /home/realcas/public_html/eshop/ecms/system/classes/photofetch.php 上 第 54 行
警告:imagepng() [function.imagepng]:gd-png 错误:setjmp 返回 错误条件 /home/realcas/public_html/eshop/ecms/system/classes/photofetch.php 上 第 54 行
警告:无法修改标头信息 - 标头已由 (输出开始于 /home/realcas/public_html/eshop/ecms/system/classes/photofetch.php:51) 在 /home/realcas/public_html/eshop/ecms/system/classes/photofetch.php 第 55 行
这是新代码
<?
include_once('database.php');
//Fetch basic Profile
class fetchphoto extends Database{
public function countrysize($id){
$this->id = $id;
$array=preg_split('#(?<!\\\)\:#',$this->id);
if($array[1] == "9177156176671")
{
$max_width = 226;
$max_height = 3000;
}
$sth = mysql_query("SELECT categoryimage FROM shop_categories WHERE id = '".$array[0]."'");
while($r = mysql_fetch_assoc($sth)) {
$blobcontents = $r["categoryimage"];
$im = imagecreatefromstring($blobcontents);
$x = imagesx($im);
$y = imagesy($im);
$ratioh = $max_height/$y;
$ratiow = $max_width/$x;
$ratio = min($ratioh, $ratiow);
// New dimensions
$width = intval($ratio*$x);
$height = intval($ratio*$y);
// Temporarily increase the memory limit to allow for larger images
ini_set('memory_limit', '32M');
// create a new blank image
$newImage = imagecreatetruecolor($width, $height);
// Copy the old image to the new image
imagecopyresampled($newImage, $img, 0, 0, 0, 0, $width, $height, $w, $y);
// Output to a temp file
imagepng($newImage, null, 10);
header('Content-type: image/png');
return $newImage;
// Free memory
imagedestroy($newImage);
}
}
}
$fetchpicture = new fetchphoto();
$fetchpicture->Connect();
$fetchpicture->DB();
$fetchpicture->countrysize($_GET['pic']);
$fetchpicture->CloseDB();
?>
【问题讨论】: