本文整理匯總了PHP中Thin\File::extension方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::extension方法的具體用法?PHP File::extension怎麽用?PHP File::extension使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Thin\File
的用法示例。
在下文中一共展示了File::extension方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: save
/**
* Save the image based on its file type.
* @param string $savePath Where to save the image
* @param int $imageQuality The output quality of the image
* @return boolean
*/
public function save($savePath, $imageQuality = 95)
{
// If the image wasn't resized, fetch original image.
if (!$this->imageResized) {
$this->imageResized = $this->image;
}
// Get extension of the output file.
$extension = Inflector::lower(File::extension($savePath));
// Create and save an image based on it's extension.
switch ($extension) {
case 'jpg':
case 'jpeg':
if (imagetypes() & IMG_JPG) {
imagejpeg($this->imageResized, $savePath, $imageQuality);
}
break;
case 'gif':
if (imagetypes() & IMG_GIF) {
imagegif($this->imageResized, $savePath);
}
break;
case 'png':
// Scale quality from 0-100 to 0-9.
$scaleQuality = round($imageQuality / 100 * 9);
// Invert quality setting as 0 is best, not 9.
$invertScaleQuality = 9 - $scaleQuality;
if (imagetypes() & IMG_PNG) {
imagepng($this->imageResized, $savePath, $invertScaleQuality);
}
break;
default:
return false;
break;
}
// Remove the resource for the resized image.
imagedestroy($this->imageResized);
return true;
}