之前調整圖像大小,該腳本將加載圖像,然後保存本地副本緩存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形象?
[resize png/jpeg image]可能的副本(http://stackoverflow.com/questions/10263171/resize-png-jpeg-image) – Orangepill
i up用函數imagecopyresampled過時我的代碼,但現在我得到一個錯誤,說該圖像無法顯示,因爲它包含錯誤。 – libertaire