我正在建造一个photoalbum。您可以上传一些图像,这些图像将被调整大小,在数据库中创建记录等。这部分有效。
然后我想给photoalbum一个缩略图,让它在概览中看起来很漂亮。 (This is the photoalbum-overview)我认为从上传的文件中自动生成缩略图更加用户友好,所以我做了一个调整图像大小和裁剪的功能,但是出错了......
当我使用该功能进入php页面时,我得到一个空白屏幕,好像有什么不对,但没有,因为该功能仍然被裁剪并调整缩略图图像的大小。此外,任何其他调用的函数都可以正常工作,但我仍然会出现空白屏幕。
当我从文件中删除裁剪/调整大小功能时,一切都会再次出现,所以无论一切正常,这个功能似乎仍然是问题!
这是我正在谈论的功能:
function uploadthumb($path1, $path2, $path3, $path4)
{
$info = getimagesize($path1);
$breedte = $info[0];
$hoogte = $info[1];
if($hoogte <= $breedte)
{
$pseudobreedte = $hoogte*(100/124);
$margin1 = ($breedte-$pseudobreedte)/2;
$margin2 = $breedte-$pseudobreedte;
$img_r = imagecreatefromjpeg($path1);
$dst_r = imagecreatetruecolor(100, 124);
imagecopyresampled($dst_r,$img_r,0,0,0,0,100,124,$pseudobreedte,$hoogte); //nr. 1
header('Content-type: image/jpeg');
imagejpeg($dst_r,$path2,90);
$img_r = imagecreatefromjpeg($path1);
$dst_r = imagecreatetruecolor(100, 124);
imagecopyresampled($dst_r,$img_r,0,0,$margin1,0,100,124,$pseudobreedte,$hoogte); //nr. 1
header('Content-type: image/jpeg');
imagejpeg($dst_r,$path3,90);
$img_r = imagecreatefromjpeg($path1);
$dst_r = imagecreatetruecolor(100, 124);
imagecopyresampled($dst_r,$img_r,0,0,$margin2,0,100,124,$pseudobreedte,$hoogte); //nr. 1
header('Content-type: image/jpeg');
imagejpeg($dst_r,$path4,90);
}
else{
$pseudohoogte = $breedte*(124/100);
$margin1 = ($hoogte-$pseudohoogte)/2;
$margin2 = $hoogte-$pseudohoogte;
$img_r = imagecreatefromjpeg($path1);
$dst_r = imagecreatetruecolor(100, 124);
imagecopyresampled($dst_r,$img_r,0,0,0,0,100,124,$breedte,$pseudohoogte); //nr. 1
header('Content-type: image/jpeg');
imagejpeg($dst_r,$path2,90);
$img_r = imagecreatefromjpeg($path1);
$dst_r = imagecreatetruecolor(100, 124);
imagecopyresampled($dst_r,$img_r,0,0,0,$margin1,100,124,$breedte,$pseudohoogte); //nr. 1
header('Content-type: image/jpeg');
imagejpeg($dst_r,$path3,90);
$img_r = imagecreatefromjpeg($path1);
$dst_r = imagecreatetruecolor(100, 124);
imagecopyresampled($dst_r,$img_r,0,0,0,$margin2,100,124,$breedte,$pseudohoogte); //nr. 1
header('Content-type: image/jpeg');
imagejpeg($dst_r,$path4,90);
}
}
$info = getimagesize($path1);
$breedte = $info[0];
$hoogte = $info[1];
if($hoogte <= $breedte)
{
$pseudobreedte = $hoogte*(100/124);
$margin1 = ($breedte-$pseudobreedte)/2;
$margin2 = $breedte-$pseudobreedte;
$img_r = imagecreatefromjpeg($path1);
$dst_r = imagecreatetruecolor(100, 124);
imagecopyresampled($dst_r,$img_r,0,0,0,0,100,124,$pseudobreedte,$hoogte); //nr. 1
header('Content-type: image/jpeg');
imagejpeg($dst_r,$path2,90);
$img_r = imagecreatefromjpeg($path1);
$dst_r = imagecreatetruecolor(100, 124);
imagecopyresampled($dst_r,$img_r,0,0,$margin1,0,100,124,$pseudobreedte,$hoogte); //nr. 1
header('Content-type: image/jpeg');
imagejpeg($dst_r,$path3,90);
$img_r = imagecreatefromjpeg($path1);
$dst_r = imagecreatetruecolor(100, 124);
imagecopyresampled($dst_r,$img_r,0,0,$margin2,0,100,124,$pseudobreedte,$hoogte); //nr. 1
header('Content-type: image/jpeg');
imagejpeg($dst_r,$path4,90);
}
else{
$pseudohoogte = $breedte*(124/100);
$margin1 = ($hoogte-$pseudohoogte)/2;
$margin2 = $hoogte-$pseudohoogte;
$img_r = imagecreatefromjpeg($path1);
$dst_r = imagecreatetruecolor(100, 124);
imagecopyresampled($dst_r,$img_r,0,0,0,0,100,124,$breedte,$pseudohoogte); //nr. 1
header('Content-type: image/jpeg');
imagejpeg($dst_r,$path2,90);
$img_r = imagecreatefromjpeg($path1);
$dst_r = imagecreatetruecolor(100, 124);
imagecopyresampled($dst_r,$img_r,0,0,0,$margin1,100,124,$breedte,$pseudohoogte); //nr. 1
header('Content-type: image/jpeg');
imagejpeg($dst_r,$path3,90);
$img_r = imagecreatefromjpeg($path1);
$dst_r = imagecreatetruecolor(100, 124);
imagecopyresampled($dst_r,$img_r,0,0,0,$margin2,100,124,$breedte,$pseudohoogte); //nr. 1
header('Content-type: image/jpeg');
imagejpeg($dst_r,$path4,90);
}
}
答案 0 :(得分:0)
我的答案很简单..我想保存三个缩略图,而我唯一做错的就是每次调用header()函数。我认为header()指定了我保存的图像,但实际上它指定了文档本身的内容类型,这使得页面变成空白。