1
我希望在調整它們的大小時保持圖像的寬高比。我需要在社交網站上顯示94000個圖像作爲預覽圖像。我得到的挑戰是一些用戶上傳了全長照片,結果它們在重新調整大小後顯得很緊張。我正在使用代碼點火器來實現這一點。文件名在數據庫表中。這是我使用Imagick照片多圖像調整大小作物沒有扭曲/拉伸php
if (file_exists($_SERVER["DOCUMENT_ROOT"]."/uploads/profiles /purchased_profiles/".$images_->_file_name)) {
//echo "The file $filename exists";
$thumb = new Imagick();
$thumb->readImage($_SERVER["DOCUMENT_ROOT"]."/uploads/profiles/purchased_profiles/".$images_->_file_name);
$orientation = $thumb->getImageOrientation();
switch($orientation) {
case imagick::ORIENTATION_BOTTOMRIGHT:
$thumb->rotateimage("#000", 180); // rotate 180 degrees
break;
case imagick::ORIENTATION_RIGHTTOP:
$thumb->rotateimage("#000", 90); // rotate 90 degrees CW
break;
case imagick::ORIENTATION_LEFTBOTTOM:
$thumb->rotateimage("#000", -90); // rotate 90 degrees CCW
break;
}
$thumb->resizeImage(160,160,Imagick::FILTER_LANCZOS,1);
$thumb->writeImage($_SERVER["DOCUMENT_ROOT"]."/uploads/profiles/purchased_profiles/160x160/".$images_->_file_name);
$thumb->clear();
$thumb->destroy();
}
謝謝你工作像魔術甚至沒有編輯你的代碼 –