本文整理汇总了PHP中Thumbnail::_coord方法的典型用法代码示例。如果您正苦于以下问题:PHP Thumbnail::_coord方法的具体用法?PHP Thumbnail::_coord怎么用?PHP Thumbnail::_coord使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thumbnail
的用法示例。
在下文中一共展示了Thumbnail::_coord方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: render
/**
* Draw thumbnail result to resource.
*
* @param mixed $input Destination image, a filename or an image string data or a GD image resource
* @param array $options Thumbnail options
*
* @return boolean TRUE on success or FALSE on failure.
* @access public
* @see Thumbnail::output()
*/
function render($input, $options = array())
{
// Create the source image
$sourceImage = Thumbnail::imageCreate($input);
if (!is_resource($sourceImage)) {
user_error('Invalid image resource', E_USER_NOTICE);
return false;
}
$sourceWidth = imagesx($sourceImage);
$sourceHeight = imagesy($sourceImage);
// Set default options
static $defOptions = array('width' => 150, 'height' => 150, 'method' => THUMBNAIL_METHOD_SCALE_MAX, 'percent' => 0, 'halign' => THUMBNAIL_ALIGN_CENTER, 'valign' => THUMBNAIL_ALIGN_CENTER);
foreach ($defOptions as $k => $v) {
if (!isset($options[$k])) {
$options[$k] = $v;
}
}
// Estimate a rectangular portion of the source image and a size of the target image
if ($options['method'] == THUMBNAIL_METHOD_CROP) {
if ($options['percent']) {
$W = floor($options['percent'] * $sourceWidth);
$H = floor($options['percent'] * $sourceHeight);
} else {
$W = $options['width'];
$H = $options['height'];
}
$width = $W;
$height = $H;
$Y = Thumbnail::_coord($options['valign'], $sourceHeight, $H);
$X = Thumbnail::_coord($options['halign'], $sourceWidth, $W);
} else {
$X = 0;
$Y = 0;
$W = $sourceWidth;
$H = $sourceHeight;
if ($options['percent']) {
$width = floor($options['percent'] * $W);
$height = floor($options['percent'] * $H);
} else {
$width = $options['width'];
$height = $options['height'];
if ($options['method'] == THUMBNAIL_METHOD_SCALE_MIN) {
$Ww = $W / $width;
$Hh = $H / $height;
if ($Ww > $Hh) {
$W = floor($width * $Hh);
$X = Thumbnail::_coord($options['halign'], $sourceWidth, $W);
} else {
$H = floor($height * $Ww);
$Y = Thumbnail::_coord($options['valign'], $sourceHeight, $H);
}
} else {
if ($H > $W) {
$width = floor($height / $H * $W);
} else {
$height = floor($width / $W * $H);
}
}
}
}
// Create the target image
if (function_exists('imagecreatetruecolor')) {
$targetImage = imagecreatetruecolor($width, $height);
} else {
$targetImage = imagecreate($width, $height);
}
if (!is_resource($targetImage)) {
user_error('Cannot initialize new GD image stream', E_USER_NOTICE);
return false;
}
// Copy the source image to the target image
if ($options['method'] == THUMBNAIL_METHOD_CROP) {
$result = imagecopy($targetImage, $sourceImage, 0, 0, $X, $Y, $W, $H);
} elseif (function_exists('imagecopyresampled')) {
$result = imagecopyresampled($targetImage, $sourceImage, 0, 0, $X, $Y, $width, $height, $W, $H);
} else {
$result = imagecopyresized($targetImage, $sourceImage, 0, 0, $X, $Y, $width, $height, $W, $H);
}
if (!$result) {
user_error('Cannot resize image', E_USER_NOTICE);
return false;
}
// Free a memory from the source image
imagedestroy($sourceImage);
// Save the resulting thumbnail
return $targetImage;
}
示例2: render
/**
* Процесс создания копии изображения с заданными параметрами
*
* @param mixed $input Имя файла, изображение-строка или GD-resource
* @param array $options Массив настроек
*
* @return resource|boolean TRUE или FALSE.
* @access public
* @see Thumbnail::output()
*/
public static function render($input, $options = array())
{
// Создаем ресурс
$sourceImage = Thumbnail::imageCreate($input);
if (!is_resource($sourceImage)) {
throw new joosImageLibrariesException('Invalid image resource');
}
$sourceWidth = imagesx($sourceImage);
$sourceHeight = imagesy($sourceImage);
// Устанавливаем настройки по-умолчанию
static $defOptions = array('width' => 150, 'height' => 150, 'method' => THUMBNAIL_METHOD_SCALE_MAX, 'percent' => 0, 'halign' => THUMBNAIL_ALIGN_CENTER, 'valign' => THUMBNAIL_ALIGN_CENTER, 'check_size' => 0, 'resize' => 1);
foreach ($defOptions as $k => $v) {
if (!isset($options[$k])) {
$options[$k] = $v;
}
}
$resize = 1;
if ($options['check_size'] == 1 && $sourceWidth <= $options['width'] && $sourceHeight <= $options['height'] || $options['resize'] == 0) {
$resize = 0;
}
if ($resize) {
// Estimate a rectangular portion of the source image and a size of the target image
if ($options['method'] == THUMBNAIL_METHOD_CROP) {
if ($options['percent']) {
$W = floor($options['percent'] * $sourceWidth);
$H = floor($options['percent'] * $sourceHeight);
} else {
$W = $options['width'];
$H = $options['height'];
}
$width = $W;
$height = $H;
$Y = Thumbnail::_coord($options['valign'], $sourceHeight, $H);
$X = Thumbnail::_coord($options['halign'], $sourceWidth, $W);
} else {
$X = 0;
$Y = 0;
$W = $sourceWidth;
$H = $sourceHeight;
if ($options['percent']) {
$width = floor($options['percent'] * $W);
$height = floor($options['percent'] * $H);
} else {
$width = $options['width'];
$height = $options['height'];
if ($options['method'] == THUMBNAIL_METHOD_SCALE_MIN) {
$Ww = $W / $width;
$Hh = $H / $height;
if ($Ww > $Hh) {
$W = floor($width * $Hh);
$X = Thumbnail::_coord($options['halign'], $sourceWidth, $W);
} else {
$H = floor($height * $Ww);
$Y = Thumbnail::_coord($options['valign'], $sourceHeight, $H);
}
} else {
if ($H > $W) {
$width = floor($height / $H * $W);
} else {
$height = floor($width / $W * $H);
}
}
}
}
} else {
$W = $sourceWidth;
$H = $sourceHeight;
$width = $sourceWidth;
$height = $sourceHeight;
$X = 0;
$Y = 0;
}
// Create the target image
if (function_exists('imagecreatetruecolor')) {
$targetImage = imagecreatetruecolor($width, $height);
} else {
$targetImage = imagecreate($width, $height);
}
if (!is_resource($targetImage)) {
throw new joosImageLibrariesException('Cannot initialize new GD image stream', E_USER_NOTICE);
return false;
}
if ($options['method'] == THUMBNAIL_METHOD_CROP && isset($options['x']) && isset($options['y'])) {
$X = $options['x'];
$Y = $options['y'];
}
// Copy the source image to the target image
if ($options['method'] == THUMBNAIL_METHOD_CROP) {
$result = imagecopy($targetImage, $sourceImage, 0, 0, $X, $Y, $W, $H);
} elseif (function_exists('imagecopyresampled')) {
//.........这里部分代码省略.........