【发布时间】:2012-02-04 21:24:37
【问题描述】:
我只有基本的 php 技能,我不得不把照片画廊放在网站上。由于这个网站会被对编程知之甚少的人使用,所以我想要一个简单的使用:上传一个包含照片的文件夹(编辑:通过FTP),照片库缩略图会自动显示,点击缩略图会显示完整大小图像。
我使用了一个即时生成缩略图的脚本。如果我直接在浏览器中调用它,这个脚本似乎工作正常。我得到我的缩略图。但是当我在我的页面中显示一个画廊时,每个图像源都是对我的脚本的调用,只显示缩略图的随机子集,其他只显示替代文本。例如,在一个 8 的画廊上,我第一次显示页面时可能只得到 3,4 和 7,而在刷新 1,3,5,6,8 后:
我找不到其他拇指未加载的错误消息,但在这里我的 php 基本技能可能会让我失败,也许我只是不知道在哪里可以找到这样的错误消息。
这是对我的脚本的调用:
<a href="resources/galleries/example.jpg"><img src="mini.php?f=example.jpg" alt="Photo" /></a>
和 mini.php 使用了 GD:
<?php
$ratio = 150;
$dir = './resources/galleries';
if (!isset($_GET['f'])) {
header('location: index.php');
exit();
}
else {
$image = $_GET['f'];
$tableau = @getimagesize($dir.'/'.$image);
if ($tableau == FALSE) {
header('location: index.php');
exit();
}
else {
// if jpeg
if ($tableau[2] == 2) {
$src = imagecreatefromjpeg($dir.'/'.$image);
if ($tableau[0] > $tableau[1]) {
$im = imagecreatetruecolor(round(($ratio/$tableau[1])*$tableau[0]), $ratio);
imagecopyresampled($im, $src, 0, 0, 0, 0, round(($ratio/$tableau[1])*$tableau[0]), $ratio, $tableau[0], $tableau[1]);
}
else {
$im = imagecreatetruecolor($ratio, round(($ratio/$tableau[0])*$tableau[1]));
imagecopyresampled($im, $src, 0, 0, 0, 0, $ratio, round($tableau[1]*($ratio/$tableau[0])), $tableau[0], $tableau[1]);
}
header ("Content-type: image/jpeg");
imagejpeg ($im);
}
elseif ($tableau[2] == 3) { // PNG
$src = imagecreatefrompng($dir.'/'.$image);
if ($tableau[0] > $tableau[1]) {
$im = imagecreatetruecolor(round(($ratio/$tableau[1])*$tableau[0]), $ratio);
imagecopyresampled($im, $src, 0, 0, 0, 0, round(($ratio/$tableau[1])*$tableau[0]), $ratio, $tableau[0], $tableau[1]);
}
else {
$im = imagecreatetruecolor($ratio, round(($ratio/$tableau[0])*$tableau[1]));
imagecopyresampled($im, $src, 0, 0, 0, 0, $ratio, round($tableau[1]*($ratio/$tableau[0])), $tableau[0], $tableau[1]);
}
header ("Content-type: image/png");
imagepng ($im);
}
}
}
?>
有什么想法吗?
【问题讨论】: