本文整理匯總了PHP中ImageManager::resizeImageWithAspectRatio方法的典型用法代碼示例。如果您正苦於以下問題:PHP ImageManager::resizeImageWithAspectRatio方法的具體用法?PHP ImageManager::resizeImageWithAspectRatio怎麽用?PHP ImageManager::resizeImageWithAspectRatio使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ImageManager
的用法示例。
在下文中一共展示了ImageManager::resizeImageWithAspectRatio方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: ImageManager
/**
* Creates a thumbnail of a picture
*
* Note that all "Path" parameters are required to bring along their
* own trailing slash.
*
* @param string $strPath
* @param string $strWebPath
* @param string $file
* @param int $maxSize The maximum width or height of the image
* @param int $quality
* @return boolean
*/
function _createThumb($strPath, $strWebPath, $file, $maxSize = 80, $quality = 90, $thumb_name = '', $generateThumbnailByRatio = false)
{
$_objImage = new ImageManager();
$file = basename($file);
$tmpSize = getimagesize($strPath . $file);
$factor = 1;
if ($tmpSize[0] > $tmpSize[1]) {
$factor = $maxSize / $tmpSize[0];
} else {
$factor = $maxSize / $tmpSize[1];
}
$thumbWidth = $tmpSize[0] * $factor;
$thumbHeight = $tmpSize[1] * $factor;
if (!$_objImage->loadImage($strPath . $file)) {
return false;
}
if ($generateThumbnailByRatio && !$_objImage->resizeImageWithAspectRatio($thumbWidth, $thumbHeight, $quality)) {
return false;
} elseif (!$generateThumbnailByRatio && !$_objImage->resizeImage($thumbWidth, $thumbHeight, $quality)) {
return false;
}
if (!(strlen($thumb_name) > 0)) {
$thumb_name = self::getThumbnailFilename($file);
}
if (!$_objImage->saveNewImage($strPath . $thumb_name)) {
return false;
}
if (!\Cx\Lib\FileSystem\FileSystem::makeWritable($strPath . $thumb_name)) {
return false;
}
return true;
}