2

我正在使用 minigal nano 0.3.6,我将图像放在照片目录中。未生成缩略图。但是,当我单击损坏的图像或缩略图时,图像本身在灯箱中打开就好了。以下是生成缩略图的代码:

此脚本和包含的文件受知识共享 ( http://creativecommons.org/licenses/by-sa/2.5/ ) 的许可您可以使用、编辑和重新分发此脚本,只要您向原作者致敬不删除指向 www.minigal.dk 的链接(“Powered by MiniGal Nano xxx”)

MiniGal Nano 由 Thomas Rybak 创建

版权所有 2010 Thomas Rybak 支持:www.minigal.dk 社区:www.minigal.dk/forum

请享受这个免费的脚本!

使用示例:文件:createthumb.php 示例:*/ // error_reporting(E_ALL);

if (preg_match("/.jpg$|.jpeg$/i", $_GET['filename'])) header('Content-type: image/jpeg'); if (preg_match("/.gif$/i", $_GET['filename'])) header('Content-type: image/gif'); if (preg_match("/.png$/i", $_GET['filename'])) header('Content-type: image/png');

// Display error image if file isn't found
if (!is_file($_GET['filename'])) {
    header('Content-type: image/jpeg');
    $errorimage = ImageCreateFromJPEG('images/questionmark.jpg');
    ImageJPEG($errorimage,null,90);
}

// Display error image if file exists, but can't be opened
if (substr(decoct(fileperms($_GET['filename'])), -1, strlen(fileperms($_GET['filename']))) < 4 OR substr(decoct(fileperms($_GET['filename'])), -3,1) < 4) {
    header('Content-type: image/jpeg');
    $errorimage = ImageCreateFromJPEG('images/cannotopen.jpg');
    ImageJPEG($errorimage,null,90);
}

// Define variables
$target = "";
$xoord = 0;
$yoord = 0;

if ($_GET['size'] == "") $_GET['size'] = 120; //
   $imgsize = GetImageSize($_GET['filename']);
   $width = $imgsize[0];
   $height = $imgsize[1];
  if ($width > $height) { // If the width is greater than the height it’s a horizontal picture
    $xoord = ceil(($width-$height)/2);
    $width = $height;      // Then we read a square frame that  equals the width
  } else {
    $yoord = ceil(($height-$width)/2);
    $height = $width;
  }

// Rotate JPG pictures
if (preg_match("/.jpg$|.jpeg$/i", $_GET['filename'])) {
    if (function_exists('exif_read_data') && function_exists('imagerotate')) {
        $exif = exif_read_data($_GET['filename']);
        $ort = $exif['IFD0']['Orientation'];
        $degrees = 0;
        switch($ort)
        {
            case 6: // 90 rotate right
                $degrees = 270;
            break;
            case 8:    // 90 rotate left
                $degrees = 90;
            break;
        }
        if ($degrees != 0)  $target = imagerotate($target, $degrees, 0);
    }
}

     $target = ImageCreatetruecolor($_GET['size'],$_GET['size']);
     if (preg_match("/.jpg$/i", $_GET['filename'])) $source = ImageCreateFromJPEG($_GET['filename']);
     if (preg_match("/.gif$/i", $_GET['filename'])) $source = ImageCreateFromGIF($_GET['filename']);
     if (preg_match("/.png$/i", $_GET['filename'])) $source = ImageCreateFromPNG($_GET['filename']);
     imagecopyresampled($target,$source,0,0,$xoord,$yoord,$_GET['size'],$_GET['size'],$width,$height);
     imagedestroy($source);

     if (preg_match("/.jpg$/i", $_GET['filename'])) ImageJPEG($target,null,90);
     if (preg_match("/.gif$/i", $_GET['filename'])) ImageGIF($target,null,90);
     if (preg_match("/.png$/i", $_GET['filename'])) ImageJPEG($target,null,90); // Using ImageJPEG on purpose
     imagedestroy($target);

?>

4

1 回答 1

1

该错误与图像中包含的 EXIF 数据有关。我有同样的问题(使用佳能相机)。希望这对你仍然有帮助。只需转到如下所示的行:

$exif = exif_read_data($_GET['filename']);

将其更改为以下内容:

$exif = @exif_read_data($_GET['filename']);

错误图像应该消失,您的缩略图应该出现。

于 2013-07-14T10:23:27.183 回答