2013-07-26 44 views
0

之前调整图像大小,该脚本将加载图像,然后保存本地副本缓存PHP:缓存

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; 
      } 

我如何可以调整在保存前300x300px形象?

+0

[resize png/jpeg image]可能的副本(http://stackoverflow.com/questions/10263171/resize-png-jpeg-image) – Orangepill

+0

i up用函数imagecopyresampled过时我的代码,但现在我得到一个错误,说该图像无法显示,因为它包含错误。 – libertaire

回答

0

ü需要使用

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

检查这个网址一旦image resize。希望它有助于充分

+0

我用函数imagecopyresampled更新了我的代码,但现在我得到一个错误,指出图像无法显示,因为它包含错误。 – libertaire

+0

你能告诉我你上传的图片类型是什么? – nickle

+0

图片可以是各种类型(gif,jpg或png)......脚本在缓存后将它们转换为PNG ......我只需要在保存之前调整PNG的大小它到缓存文件夹(pochette_album /) – libertaire