本文整理汇总了PHP中Intervention\Image\Image::grab方法的典型用法代码示例。如果您正苦于以下问题:PHP Image::grab方法的具体用法?PHP Image::grab怎么用?PHP Image::grab使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Intervention\Image\Image
的用法示例。
在下文中一共展示了Image::grab方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: transform
/**
* Transform the image
*
* @param Image $image
* @return Image
*/
public function transform(Image $image)
{
if ($this->width and $this->height) {
$image->grab($this->width, $this->height);
} elseif ($this->width or $this->height) {
$image->resize($this->width, $this->height, true, false);
}
return $image;
}
示例2: createVariation
/**
* {@inheritdoc}
*/
public function createVariation(ImageFormat $output_format, $quality, ImageDimensions $dimensions = null, ImageCropDimensions $crop_dimensions = null)
{
try {
$img = new InterventionImage($this->data);
} catch (\Intervention\Image\Exception\InvalidImageDataStringException $e) {
throw new BadImageException('Bad image data', 0, $e);
} catch (\Intervention\Image\Exception\ImageNotFoundException $e) {
throw new BadImageException('Not an image', 0, $e);
}
if ($dimensions) {
if ($dimensions->getGrab()) {
$img->grab($dimensions->getWidth(), $dimensions->getHeight());
} else {
$img->resize($dimensions->getWidth(), $dimensions->getHeight(), $dimensions->getMaintainRatio(), $dimensions->canUpscale());
}
}
return $img->encode($output_format->key(), $quality);
}
示例3: grab
/**
* Cut out a detail of the image in given ratio and resize to output size
*
* @param integer $width
* @param integer $height
* @return \Intervention\Image\Image
* @static
*/
public static function grab($width = null, $height = null)
{
return \Intervention\Image\Image::grab($width, $height);
}
示例4: missingMethod
public function missingMethod($args)
{
if (count($args) < 3) {
return parent::missingMethod($args);
}
if ($args[0] == 'force') {
array_shift($args);
}
$modelKeyword = $args[0];
$modelClass = \Devhook::getClassByKey($modelKeyword);
$id = $args[1];
$file = $args[2];
$parts = explode('-', $file);
if (count($parts) == 3) {
list($field, $sizeKey, $file) = $parts;
@(list($imageId, $ext) = explode('.', $file));
} else {
$imageId = false;
@(list($field, $file) = $parts);
@(list($sizeKey, $ext) = explode('.', $file));
}
if (!$field || !$sizeKey || $ext != 'jpg') {
return parent::missingMethod($args);
}
$model = $modelClass::find($id);
if (!$model || !$model->{$field}) {
return parent::missingMethod($args);
}
// $fileExt = pathinfo($model->$field, PATHINFO_EXTENSION);
$fields = (array) $model->getFields();
$modelField = isset($fields[$field]) ? $fields[$field] : false;
if (!$modelField || empty($modelField->type)) {
return parent::missingMethod($args);
}
$imageTypes = array('image');
$type = $modelField->type;
$sizes = (array) $modelField->settings('sizes');
$imageAdminThumb = Config::get('devhook.imageAdminThumb');
if (!in_array($type, $imageTypes) || empty($sizes[$sizeKey])) {
return parent::missingMethod($args);
}
$watermark = $modelField->settings('watermark');
$size = $sizes[$sizeKey];
$width = $size[0];
$hegiht = $size[1];
$crop = isset($size[2]) ? $size[2] : false;
$quality = isset($size[3]) ? $size[3] : 95;
if ($imageId) {
$imageFile = \Image::where('imageable_type', $modelKeyword)->where('imageable_id', $id)->find($imageId);
if (!$imageFile) {
return parent::missingMethod($args);
}
$imageFile = $imageFile->path;
} else {
$imageFile = $model->{$field};
}
ini_set('memory_limit', '200M');
$image = new IMG(public_path($imageFile));
if ($crop) {
$image->grab($width, $hegiht);
} else {
$image->resize($width, $hegiht, true);
}
if ($watermark) {
if (!$watermark['sizes'] || in_array($sizeKey, $watermark['sizes'])) {
$image->insert($watermark['image'], $watermark['offset'][0], $watermark['offset'][1], $watermark['position']);
}
}
$tmpFile = public_path($model->{$field}) . '.tmp_' . uniqid();
$newFile = public_path(Config::get('devhook.imageRoute') . '/' . implode('/', $args));
$newPath = dirname($newFile);
if (!File::exists($newPath)) {
File::makeDirectory($newPath, 0777, true);
}
$image->save($newFile, $quality);
$img = $image->encode($ext, $quality);
$response = Response::make($img, 200);
$response->header('Content-Type', 'image/jpeg');
return $response;
}