0
問候...我通過目錄即時調整JPG大小。照片本質上是隨機水平或垂直的。我的腳本(如下所示)按預期工作 - 除了一個特定情況。這種情況下,我將照片直接從存儲卡傳輸到創建拇指的最終目錄。在這種情況下 - 我的垂直照片會生成水平大拇指。PHP創建縮略圖,垂直圖像更改爲水平
如果我處理已處理,調整大小或不是這樣的圖像的文件夾,則不會發生此問題。垂直照片在相機上,記憶卡上旋轉,這一事實證明,在我的本地驅動器上,垂直預覽爲垂直。但是,如果我通過縮略圖腳本運行未觸及的文件,它會順時針旋轉垂直90度!
有沒有人聰明有沒有什麼想法? :)
另外我玩弄了在我的界面放置'旋轉'按鈕的想法,但我無法讓PHP函數rotateimage()工作。示例是simle ...沒有錯誤,但在瀏覽器中,我得到了一個符號和文本的英里。以前見過嗎?
謝謝。
function createThumbs($pathToImages, $pathToThumbs, $thumbWidth)
{
// open the directory
$dir = opendir($pathToImages);
// loop through it, looking for any/all JPG files:
while (false !== ($fname = readdir($dir))) {
// parse path for the extension
$info = pathinfo($pathToImages . $fname);
// continue only if this is a JPEG image
if (strtolower($info['extension']) == 'jpg')
{
echo "Creating thumbnail for {$fname} <br />";
// load image and get image size
$img = imagecreatefromjpeg("{$pathToImages}{$fname}");
$width = imagesx($img);
$height = imagesy($img);
// calculate thumbnail size
$new_width = $thumbWidth;
$new_height = floor($height * ($thumbWidth/$width));
// create a new tempopary image
$tmp_img = imagecreatetruecolor($new_width, $new_height);
// copy and resize old image into new image
//imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// save thumbnail into a file
imagejpeg($tmp_img, "{$pathToThumbs}{$fname}");
}
}
// close the directory
closedir($dir);
}
「垂直」和「水平」是指照相機拍攝時的方向嗎? – Charles 2011-03-16 19:22:34