【发布时间】:2016-09-11 11:10:18
【问题描述】:
我希望在调整图像大小时保持图像的纵横比。我有 94 000 张图像需要在社交网站上显示为预览图像。我遇到的挑战是一些用户上传了全长照片,结果它们在重新调整大小后显得拉伸。我正在使用 codeigniter 来实现这一点。文件名在数据库表中。这是我正在使用的代码
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();
}
【问题讨论】:
标签: imagick codeigniter-3 aspect-ratio