对于那些可能已经读过我之前几分钟前解决的问题的人,>.<
动态的php脚本运行的很好,但是当我把新图片上传到自己制作的图库时,图片的大小被调整到了150x150,这是我想要的……然而,当涉及到添加新图像时,它都是黑色的……

正如您所看到的,上传到文件夹的三个黑色图像和添加到数据库的目录。
其他(非黑色图像)已经使用image.php调整了大小。
是什么导致了这种情况?
如果我查看源代码,代码是好的.PHP中的while循环生成如下所示的输出:
<div class="view-wrap" id="photo-10">
<div class="view-icon">
<div class="img-label">
<a href="#" id="10" class="delete"><img src="img/small-delete.png" /> Delete</a>
</div>
<a href="img/events/Paintballing/24251_1395408043148_1170626626_1204038_5382765_n.jpg">
<img src="image.php?dir=img/events/Paintballing/24251_1395408043148_1170626626_1204038_5382765_n.jpg" alt="" width="110" height="110" />
</a>
</div>
</div>一个区块的示例。
如果我查看源代码(在Firefox中)并按示例单击image.php?dir=img/events/Paintballing/24251_1395408043148_1170626626_1204038_5382765_n.jpg,我可以看到150x150大小的缩略图,但在布局中,它显示了一个黑色的缩略图……
有人知道为什么会这样吗?
编辑:
<?php
$dir = $_GET['dir'];
header('Content-type: image/jpeg');
$create = imagecreatetruecolor(150, 150);
$img = imagecreatefromjpeg($dir);
list($width, $height) = getimagesize($dir);
imagecopyresampled($create, $img, 0, 0, 0, 0, 150, 150, $width, $height);
imagejpeg($create, null, 100);
?>这是image.php。
发布于 2010-05-31 05:11:13
感谢您更新您的帖子。
你确定图片是你上传的jpg/jpeg格式吗?
尝试更改为以下内容
<?php
$dir = $_GET['dir'];
$ext = strtoupper(pathinfo($dir, PATHINFO_EXTENSION));
switch($ext)
{
case 'jpeg':
case 'jpg':
$img = imagecreatefromjpeg($dir);
break;
case 'png':
$img = imagecreatefrompng($dir);
break;
case 'gif':
$img = imagecreatefromgif($dir);
break;
}
if(isset(img))
{
header('Content-type: image/jpeg');
$create = imagecreatetruecolor(150, 150);
list($width, $height) = getimagesize($dir);
imagecopyresampled($create, $img, 0, 0, 0, 0, 150, 150, $width, $height);
imagejpeg($create, null, 100);
}else
{
echo sprintf('Unable to process image, Unknown format %s',$ext);
}
?>发布于 2010-06-08 05:13:01
与其拉伸图像,为什么不添加一个边框呢?
下面是函数
function resize_to_canvas($filename,$canvas_w=100,$canvas_h=225){
list($width, $height, $type) = getimagesize($filename);
$original_overcanvas_w = $width/$canvas_w;
$original_overcanvas_h = $height/$canvas_h;
$dst_w = round($width/max($original_overcanvas_w,$original_overcanvas_h),0);
$dst_h = round($height/max($original_overcanvas_w,$original_overcanvas_h),0);
$dst_image = imagecreatetruecolor($canvas_w, $canvas_h);
$background = imagecolorallocate($dst_image, 255, 255, 255);
imagefill($dst_image, 0, 0, $background);
$src_image = imagecreatefromjpeg($filename);
imagecopyresampled($dst_image, $src_image, ($canvas_w-$dst_w)/2, ($canvas_h-$dst_h)/2, 0, 0, $dst_w, $dst_h, $width, $height);
imagegif($dst_image, $filename);
imagedestroy($dst_image);}此函数将替换原始文件,但很容易修改以创建新的缩略图图像。只需将文件名改为imagegif($dst_image,$filename)行;
https://stackoverflow.com/questions/2940319
复制相似问题