【问题标题】:php : resize image before cachingphp : 在缓存之前调整图像大小
【发布时间】:2013-07-26 06:18:18
【问题描述】:

此脚本将加载图像,然后保存本地副本以进行缓存

header('Content-Type: image/png');

            $imgpochette = $_GET['i'];

            $ENABLE_CACHE = true;
            $CACHE_TIME_HOURS = 744;
            $CACHE_FILE_PATH = "pochette_album/$imgpochette.png";

            if($ENABLE_CACHE && file_exists($CACHE_FILE_PATH) && (time() - filemtime($CACHE_FILE_PATH) < ($CACHE_TIME_HOURS * 60 * 60))) {
              echo @file_get_contents($CACHE_FILE_PATH);
            } else {
                    // Load the requested image
                    $imgdisplay = "http://www.pirate-punk.com/pochette.php?i=$imgpochette&display=1";
                    $image = imagecreatefromstring(file_get_contents($imgdisplay));
$width = "30";
$height = "30";
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, $image.getWidth(), $image.getHeight());
                    // Send the image
                    imagejpeg($image, $CACHE_FILE_PATH);
                    exit();
              @file_put_contents($CACHE_FILE_PATH, $output);
              echo $output;
            }

如何在保存之前将图像调整为 300x300 像素?

【问题讨论】:

  • resize png/jpeg image的可能重复
  • 我用函数 imagecopyresampled 更新了我的代码,但现在我收到一条错误消息,指出图像无法显示,因为它包含错误。

标签: php image caching png jpeg


【解决方案1】:

你需要使用

imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

检查此网址一次image resize.希望它对您有帮助

【讨论】:

  • 我用函数 imagecopyresampled 更新了我的代码,但现在我收到一条错误消息,指出图像无法显示,因为它包含错误。
  • 你能告诉我你上传的是哪种类型的图片
  • 图像可以是各种类型(gif、jpg 或 png)...脚本在缓存它们后将它们转换为 PNG...我只需要在将 PNG 保存到缓存之前调整其大小文件夹(pochette_album/)
猜你喜欢
  • 2011-04-16
  • 2015-12-05
  • 2012-12-14
  • 2011-09-01
  • 1970-01-01
  • 2011-05-17
  • 2016-12-22
  • 2012-09-27
  • 1970-01-01
相关资源
最近更新 更多