$sourcePath = 'images/'; // Path of original image
$sourceUrl = '';
$sourceName = 'photo1.jpg'; // Name of original image
$thumbPath = 'thumbs/'; // Writeable thumb path
$thumbUrl = 'thumbs/';
$thumbName = "test_thumb.jpg"; // Tip: Name dynamically
$thumbWidth = 100; // Intended dimension of thumb
// Beyond this point is simply code.
$sourceImage = imagecreatefromjpeg("$sourcePath/$sourceName");
$sourceWidth = imagesx($sourceImage);
$sourceHeight = imagesy($sourceImage);
$targetImage = imagecreate($thumbWidth,$thumbWidth);
imagecopyresized($targetImage,$sourceImage,0,0,0,0,$thumbWidth,$thumbWidth,imagesx($sourceImage),imagesy($sourceImage));
imagejpeg($targetImage, "$thumbPath/$thumbName");
// By now, the thumbnail is copied into the $thumbpath
// as the file name specified in $thumbName, so display
echo "<img src='$thumbUrl$thumbName' alt=''>";
上面的代碼給了我一個縮略圖,這很好,但圖像質量很糟糕。它看起來像圖像有倒置的顏色,看起來它已被壓扁。我整天都在頭痛。有人有主意嗎?使用PHP生成縮略圖會導致圖像質量不佳
此挑選出質量,三江源非常感謝!任何關於壓扁的想法? – Drew 2008-11-18 12:11:10
壓扁 - 是的。看到我的答案。 – philistyne 2008-11-18 12:55:13