我已經得到了下面的一段代碼:GD調整圖片大小不工作PHP
$biggest = ($width > $height) ? $width : $height;
$newWidth = 0;
$newHeight = 0;
if($biggest > $divSize){
echo "BIGGEST<br />";
$scale = $divSize/$biggest;
$newWidth = floor($width * $scale);
$newHeight = floor($height * $scale);
} else if($biggest < $divSize){
echo "DIVSIZE<br />";
$scale = $biggest/$divSize;
$newWidth = floor($width * $scale);
$newHeight = floor($height * $scale);
}
echo "SCALE: ".$scale."<br />";
echo "BIGGEST: ".$biggest."<br />";
echo "WIDTH: ".$width."<br />";
echo "HEIGHT: ".$height."<br />";
echo "NEWWIDTH: ".$newWidth."<br />";
echo "NEWHEIGHT: ".$newHeight."<br />";
$sourceImage = imagecreatefromstring(file_get_contents($fileName));
$thumb = imagecreatetruecolor($newWidth, $newHeight);
imagecopyresampled($thumb, $sourceImage, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
imagedestroy($sourceImage);
這段代碼工作正常的一些圖片,但不是所有的人。
我有與64的尺寸股利提高64
因爲他們規模完全正常的一些圖片,但對某些圖像輸出圖像的高度也64PX又該由例如32PX。
我不知道是什麼原因導致此問題。
如果您需要更多信息,請詢問。
我很抱歉,但我不 得到它。你的功能做了什麼,然後我的功能呢? 我的函數創建一個適合給定尺寸的縮略圖。我用css把拇指放在中間。 我認爲,無論您使用GD還是CSS來定位拇指,它都是一種品味問題。現在我的圖像越小越好。 – MmynameStackflow
請讓現在認識你的功能有什麼好處? – MmynameStackflow
它使用固定的寬度和高度。如果您在表格中顯示這些圖像,則避免有時會出現大列,有時候會出現高列:您總是會獲得相同的大小。 –