本文整理汇总了PHP中FileHandler::checkMemoryLoadImage方法的典型用法代码示例。如果您正苦于以下问题:PHP FileHandler::checkMemoryLoadImage方法的具体用法?PHP FileHandler::checkMemoryLoadImage怎么用?PHP FileHandler::checkMemoryLoadImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileHandler
的用法示例。
在下文中一共展示了FileHandler::checkMemoryLoadImage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createImageFile
/**
* Moves an image file (resizing is possible)
*
* @param string $source_file Path of the source file
* @param string $target_file Path of the target file
* @param int $resize_width Width to resize
* @param int $resize_height Height to resize
* @param string $target_type If $target_type is set (gif, jpg, png, bmp), result image will be saved as target type
* @param string $thumbnail_type Thumbnail type(crop, ratio)
* @return bool true: success, false: failed
**/
function createImageFile($source_file, $target_file, $resize_width = 0, $resize_height = 0, $target_type = '', $thumbnail_type = 'crop')
{
$source_file = FileHandler::getRealPath($source_file);
$target_file = FileHandler::getRealPath($target_file);
if (!file_exists($source_file)) {
return;
}
if (!$resize_width) {
$resize_width = 100;
}
if (!$resize_height) {
$resize_height = $resize_width;
}
// retrieve source image's information
$imageInfo = getimagesize($source_file);
if (!FileHandler::checkMemoryLoadImage($imageInfo)) {
return false;
}
list($width, $height, $type, $attrs) = $imageInfo;
if ($width < 1 || $height < 1) {
return;
}
switch ($type) {
case '1':
$type = 'gif';
break;
case '2':
$type = 'jpg';
break;
case '3':
$type = 'png';
break;
case '6':
$type = 'bmp';
break;
default:
return;
break;
}
// if original image is larger than specified size to resize, calculate the ratio
if ($resize_width > 0 && $width >= $resize_width) {
$width_per = $resize_width / $width;
} else {
$width_per = 1;
}
if ($resize_height > 0 && $height >= $resize_height) {
$height_per = $resize_height / $height;
} else {
$height_per = 1;
}
if ($thumbnail_type == 'ratio') {
if ($width_per > $height_per) {
$per = $height_per;
} else {
$per = $width_per;
}
$resize_width = $width * $per;
$resize_height = $height * $per;
} else {
if ($width_per < $height_per) {
$per = $height_per;
} else {
$per = $width_per;
}
}
if (!$per) {
$per = 1;
}
// get type of target file
if (!$target_type) {
$target_type = $type;
}
$target_type = strtolower($target_type);
// create temporary image with target size
if (function_exists('imagecreatetruecolor')) {
$thumb = imagecreatetruecolor($resize_width, $resize_height);
} else {
if (function_exists('imagecreate')) {
$thumb = imagecreate($resize_width, $resize_height);
} else {
return false;
}
}
if (!$thumb) {
return false;
}
$white = imagecolorallocate($thumb, 255, 255, 255);
imagefilledrectangle($thumb, 0, 0, $resize_width - 1, $resize_height - 1, $white);
// create temporary image having original type
//.........这里部分代码省略.........