本文整理汇总了PHP中imagick::extentImage方法的典型用法代码示例。如果您正苦于以下问题:PHP imagick::extentImage方法的具体用法?PHP imagick::extentImage怎么用?PHP imagick::extentImage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imagick
的用法示例。
在下文中一共展示了imagick::extentImage方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _resizeImagick
public function _resizeImagick(Model $model, $field, $path, $size, $geometry, $thumbnailPath)
{
$srcFile = $path . $model->data[$model->alias][$field];
$pathInfo = $this->_pathinfo($srcFile);
$thumbnailType = $imageFormat = $this->settings[$model->alias][$field]['thumbnailType'];
$isMedia = $this->_isMedia($model, $this->runtime[$model->alias][$field]['type']);
$image = new imagick();
if ($isMedia) {
$image->setResolution(300, 300);
$srcFile = $srcFile . '[0]';
}
$image->readImage($srcFile);
$height = $image->getImageHeight();
$width = $image->getImageWidth();
if (preg_match('/^\\[[\\d]+x[\\d]+\\]$/', $geometry)) {
// resize with banding
list($destW, $destH) = explode('x', substr($geometry, 1, strlen($geometry) - 2));
$image->thumbnailImage($destW, $destH, true);
$imageGeometry = $image->getImageGeometry();
$x = ($imageGeometry['width'] - $destW) / 2;
$y = ($imageGeometry['height'] - $destH) / 2;
$image->setGravity(Imagick::GRAVITY_CENTER);
$image->extentImage($destW, $destH, $x, $y);
} elseif (preg_match('/^[\\d]+x[\\d]+$/', $geometry)) {
// cropped resize (best fit)
list($destW, $destH) = explode('x', $geometry);
$image->cropThumbnailImage($destW, $destH);
} elseif (preg_match('/^[\\d]+w$/', $geometry)) {
// calculate heigh according to aspect ratio
$image->thumbnailImage((int) $geometry - 1, 0);
} elseif (preg_match('/^[\\d]+h$/', $geometry)) {
// calculate width according to aspect ratio
$image->thumbnailImage(0, (int) $geometry - 1);
} elseif (preg_match('/^[\\d]+l$/', $geometry)) {
// calculate shortest side according to aspect ratio
$destW = 0;
$destH = 0;
$destW = $width > $height ? (int) $geometry - 1 : 0;
$destH = $width > $height ? 0 : (int) $geometry - 1;
$imagickVersion = phpversion('imagick');
$image->thumbnailImage($destW, $destH, !($imagickVersion[0] == 3));
}
if ($isMedia) {
$thumbnailType = $imageFormat = $this->settings[$model->alias][$field]['mediaThumbnailType'];
}
if (!$thumbnailType || !is_string($thumbnailType)) {
try {
$thumbnailType = $imageFormat = $image->getImageFormat();
// Fix file casing
while (true) {
$ext = false;
$pieces = explode('.', $srcFile);
if (count($pieces) > 1) {
$ext = end($pieces);
}
if (!$ext || !strlen($ext)) {
break;
}
$low = array('ext' => strtolower($ext), 'thumbnailType' => strtolower($thumbnailType));
if ($low['ext'] == 'jpg' && $low['thumbnailType'] == 'jpeg') {
$thumbnailType = $ext;
break;
}
if ($low['ext'] == $low['thumbnailType']) {
$thumbnailType = $ext;
}
break;
}
} catch (Exception $e) {
$this->log($e->getMessage(), 'upload');
$thumbnailType = $imageFormat = 'png';
}
}
$fileName = str_replace(array('{size}', '{filename}', '{primaryKey}'), array($size, $pathInfo['filename'], $model->id), $this->settings[$model->alias][$field]['thumbnailName']);
$destFile = "{$thumbnailPath}{$fileName}.{$thumbnailType}";
$image->setImageCompressionQuality($this->settings[$model->alias][$field]['thumbnailQuality']);
$image->setImageFormat($imageFormat);
if (!$image->writeImage($destFile)) {
return false;
}
$image->clear();
$image->destroy();
return true;
}