本文整理汇总了PHP中CKFinder_Connector_Utils_Misc::imageCreateFromBmp方法的典型用法代码示例。如果您正苦于以下问题:PHP CKFinder_Connector_Utils_Misc::imageCreateFromBmp方法的具体用法?PHP CKFinder_Connector_Utils_Misc::imageCreateFromBmp怎么用?PHP CKFinder_Connector_Utils_Misc::imageCreateFromBmp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CKFinder_Connector_Utils_Misc
的用法示例。
在下文中一共展示了CKFinder_Connector_Utils_Misc::imageCreateFromBmp方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createThumb
/**
* Create thumbnail
*
* @param string $sourceFile
* @param string $targetFile
* @param int $maxWidth
* @param int $maxHeight
* @param boolean $preserverAspectRatio
* @param boolean $bmpSupported
* @return boolean
* @static
* @access public
*/
public static function createThumb($sourceFile, $targetFile, $maxWidth, $maxHeight, $quality, $preserverAspectRatio, $bmpSupported = false)
{
$sourceImageAttr = @getimagesize($sourceFile);
if ($sourceImageAttr === false) {
return false;
}
$sourceImageWidth = isset($sourceImageAttr[0]) ? $sourceImageAttr[0] : 0;
$sourceImageHeight = isset($sourceImageAttr[1]) ? $sourceImageAttr[1] : 0;
$sourceImageMime = isset($sourceImageAttr["mime"]) ? $sourceImageAttr["mime"] : "";
$sourceImageBits = isset($sourceImageAttr["bits"]) ? $sourceImageAttr["bits"] : 8;
$sourceImageChannels = isset($sourceImageAttr["channels"]) ? $sourceImageAttr["channels"] : 3;
if (!$sourceImageWidth || !$sourceImageHeight || !$sourceImageMime) {
return false;
}
$iFinalWidth = $maxWidth == 0 ? $sourceImageWidth : $maxWidth;
$iFinalHeight = $maxHeight == 0 ? $sourceImageHeight : $maxHeight;
if ($sourceImageWidth <= $iFinalWidth && $sourceImageHeight <= $iFinalHeight) {
if ($sourceFile != $targetFile) {
copy($sourceFile, $targetFile);
}
return true;
}
if ($preserverAspectRatio) {
// Gets the best size for aspect ratio resampling
$oSize = CKFinder_Connector_CommandHandler_Thumbnail::GetAspectRatioSize($iFinalWidth, $iFinalHeight, $sourceImageWidth, $sourceImageHeight);
} else {
$oSize = array('Width' => $iFinalWidth, 'Height' => $iFinalHeight);
}
CKFinder_Connector_Utils_Misc::setMemoryForImage($sourceImageWidth, $sourceImageHeight, $sourceImageBits, $sourceImageChannels);
switch ($sourceImageAttr['mime']) {
case 'image/gif':
if (@imagetypes() & IMG_GIF) {
$oImage = @imagecreatefromgif($sourceFile);
} else {
$ermsg = 'GIF images are not supported';
}
break;
case 'image/jpeg':
if (@imagetypes() & IMG_JPG) {
$oImage = @imagecreatefromjpeg($sourceFile);
} else {
$ermsg = 'JPEG images are not supported';
}
break;
case 'image/png':
if (@imagetypes() & IMG_PNG) {
$oImage = @imagecreatefrompng($sourceFile);
} else {
$ermsg = 'PNG images are not supported';
}
break;
case 'image/wbmp':
if (@imagetypes() & IMG_WBMP) {
$oImage = @imagecreatefromwbmp($sourceFile);
} else {
$ermsg = 'WBMP images are not supported';
}
break;
case 'image/bmp':
/*
* This is sad that PHP doesn't support bitmaps.
* Anyway, we will use our custom function at least to display thumbnails.
* We'll not resize images this way (if $sourceFile === $targetFile),
* because user defined imagecreatefrombmp and imagecreatebmp are horribly slow
*/
if ($bmpSupported && @imagetypes() & IMG_JPG && $sourceFile != $targetFile) {
$oImage = CKFinder_Connector_Utils_Misc::imageCreateFromBmp($sourceFile);
} else {
$ermsg = 'BMP/JPG images are not supported';
}
break;
default:
$ermsg = $sourceImageAttr['mime'] . ' images are not supported';
break;
}
if (isset($ermsg) || false === $oImage) {
return false;
}
$oThumbImage = imagecreatetruecolor($oSize["Width"], $oSize["Height"]);
if ($sourceImageAttr['mime'] == 'image/png') {
$bg = imagecolorallocatealpha($oThumbImage, 255, 255, 255, 127);
// (PHP 4 >= 4.3.2, PHP 5)
imagefill($oThumbImage, 0, 0, $bg);
imagealphablending($oThumbImage, false);
imagesavealpha($oThumbImage, true);
}
//imagecopyresampled($oThumbImage, $oImage, 0, 0, 0, 0, $oSize["Width"], $oSize["Height"], $sourceImageWidth, $sourceImageHeight);
//.........这里部分代码省略.........