本文整理汇总了PHP中Intervention\Image\ImageManager::make方法的典型用法代码示例。如果您正苦于以下问题:PHP ImageManager::make方法的具体用法?PHP ImageManager::make怎么用?PHP ImageManager::make使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Intervention\Image\ImageManager
的用法示例。
在下文中一共展示了ImageManager::make方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Perform image manipulations.
* @param string $source Source image binary data.
* @param array $params The manipulation params.
* @return string Manipulated image binary data.
*/
public function run($source, array $params)
{
$image = $this->imageManager->make($source);
foreach ($this->manipulators as $manipulator) {
$manipulator->setParams($params);
$image = $manipulator->run($image);
}
return $image->getEncoded();
}
示例2: processAvatar
public function processAvatar($path)
{
$manager = $this->imgManager->make($path);
$manager->orientate();
$manager->fit($this->width);
$name = $this->getFileName();
$manager->save($this->getUploadPath($name));
return $name;
}
示例3: store
/**
* Proccess image and write the text
* Verify if the image needs to be downloaded
* @param Request $request
*/
public function store(Request $request)
{
$validator = Validator::make($request->all(), ['top' => 'max:' . Image::$maxCharCount, 'bottom' => 'required|max:' . Image::$maxCharCount, 'image' => 'required']);
if ($validator->fails()) {
$errors = '';
foreach ($validator->errors()->all() as $error) {
$errors .= "<br/>" . $error;
}
return response('Erro(s) de validação: ' . $errors, 500);
}
$image = $request->get('image');
if (substr($image, -4) !== '.jpg') {
$image .= '.jpg';
}
$imageObject = $this->manager->make(public_path() . '/images/' . $image);
$token = Image::generateImageToken();
$path = public_path() . '/images/' . $token . '.jpg';
$imageObject = $this->write($imageObject, $request->get('bottom'));
if ($request->get('top')) {
$imageObject = $this->write($imageObject, $request->get('top'), 'top');
}
$result = $imageObject->save($path);
if ($result) {
return ['message' => 'Your image was saved successfully', 'token' => $token, 'image_src' => asset('images/' . $token . '.jpg')];
}
}
示例4: resize
public function resize($image)
{
$width = config('medias.max_size.width');
$height = config('medias.max_size.height');
// this orientate method needs to be called because sometimes
// images uploaded came rotated, but need to be ajusted
$img = $this->image->make(Storage::disk(config('medias.disk'))->get($image))->orientate();
if ($img->width() <= $width && $img->height() <= $height) {
return;
}
if ($img->width() > $width && $img->height() > $height) {
$img->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
});
Storage::disk(config('medias.disk'))->put($image, $img->stream());
return;
}
if ($img->width() > $width) {
$height = null;
} elseif ($img->height() > $height) {
$width = null;
}
$img->resize($width, $height, function ($constraint) {
$constraint->aspectRatio();
});
Storage::disk(config('medias.disk'))->put($image, $img->stream());
}
示例5: execute
/**
* {@inheritdoc}
*/
public function execute(CommandParams $params, CommandExecutionContext $executionContext)
{
$fileName = $params->getFirstArgument();
if (!$executionContext->hasFileInWorkingDirectory($fileName)) {
throw new ExecutionFailedException("File '{$fileName}' does not exist.");
}
$img = $this->imageManager->make($executionContext->getPathOfFileInWorkingDirectory($fileName));
if (!$params->hasSecondArgument()) {
return $this->returnImage($img, $params);
}
list($width, $height) = $this->parseDimension($params->getSecondArgument());
switch ($params->getThirdArgument()) {
case 'stretch':
$img->resize($width, $height);
break;
case 'fit':
$img->fit($width, $height);
break;
case 'crop':
$x = $this->filterIntOrNullArgument($params->getArgument(3));
$y = $this->filterIntOrNullArgument($params->getArgument(4));
$img->crop($width, $height, $x, $y);
break;
default:
$img->resize($width, $height, function (Constraint $constraint) {
$constraint->aspectRatio();
});
break;
}
return $this->returnImage($img, $params);
}
示例6: apply
/**
* {@inheritdoc}
*/
public function apply($source, $options)
{
$options = $this->parseOptions($options);
$image = $this->imageManager->make($source);
$image->crop($options['width'], $options['height'], $options['x'], $options['y']);
return $image->encode($image->mime())->getEncoded();
}
示例7: run
/**
* Perform image manipulations.
* @param Request $request The request object.
* @param string $source Source image binary data.
* @return string Manipulated image binary data.
*/
public function run(Request $request, $source)
{
$image = $this->imageManager->make($source);
foreach ($this->manipulators as $manipulator) {
$image = $manipulator->run($request, $image);
}
return $image->getEncoded();
}
示例8: apply
public function apply($source, $options)
{
$options = $this->parseOptions($options);
$image = $this->imageManager->make($source);
$image->fit($options['width'], $options['height'], function ($constraint) {
$constraint->upsize();
}, $options['position']);
return $image->encode($image->mime())->getEncoded();
}
示例9: makeImage
/**
* Make an image object from uploaded image
*
* @param string $image
* @return \Intervention\Image\ImageManager|null
*/
public function makeImage($image = '')
{
try {
//Make image object and return
return $this->image->make($image);
} catch (Exception $e) {
//Unexpected error
return null;
}
}
示例10: saveFromString
/**
* Make and save image to filesystem from base64 encoded string.
*
* @param string $string
* @param string $path
*
* @return Intervention\Image\Image
*/
public function saveFromString($string, $path, $aspectRatio = false, $width = 320, $height = 200)
{
$string = preg_replace('/data:image\\/.+?;base64,/', '', $string);
$img = imagecreatefromstring(base64_decode($string));
if ($aspectRatio) {
return $this->manager->make($img)->resize($width, $height, function ($contstraint) {
$contstraint->aspectRatio();
})->save($path);
} else {
return $this->manager->make($img)->resize($width, $height)->save($path);
}
}
示例11: process
/**
* Run the named template against the image
* @param String $template The template to run
* @return Intervention\Image\Image The processed image
*/
public function process(TemplateInterface $template)
{
// Create a new intervention image object
$image = $this->imageManager->make($this->image);
$image = $template->process($image);
// Encode the image if it hasn't
// been encoded in the template.
if (!$image->isEncoded()) {
$image->encode();
}
return $image;
}
示例12: validateFile
private function validateFile(BackdropUploadStrategy $strategy, string $tmpFile)
{
if (filesize($tmpFile) > $strategy->getMaxFileSize()) {
throw new TooBigFileException(sprintf('File is too big'));
}
$image = $this->imageManager->make($tmpFile);
if ($image->getWidth() < $strategy->getMinImageWidth() || $image->getHeight() < $strategy->getMinImageHeight()) {
throw new InvalidSizeException('Image is too small');
}
if ($image->getWidth() > $strategy->getMaxImageWidth() || $image->getHeight() > $strategy->getMaxImageHeight()) {
throw new InvalidSizeException('Image is too big');
}
}
示例13: thumb
public function thumb($width = null, $height = null)
{
$manager = new ImageManager();
$thumb = new PdfThumbnail($this->asset);
if ($width && $height) {
$image = $manager->cache(function ($manager) use($width, $height, $thumb) {
return $manager->make($thumb->getAndMakeFilename())->fit($width, $height);
});
} else {
$image = $manager->make($thumb->getAndMakeFilename())->encode();
}
return $this->response->header('content-type', 'image/png')->setContent($image);
}
示例14: view
public function view($width = null, $height = null)
{
$filename = $this->asset->exists() ? $this->asset->getFilename() : __DIR__ . '/../../../../vendor/boomcms/boom-core/img/placeholder.png';
if ($width || $height) {
$image = $this->manager->cache(function ($manager) use($width, $height, $filename) {
return $manager->make($filename)->resize($width != 0 ? $width : null, $height != 0 ? $height : null, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->encode($this->encoding);
});
} else {
$image = $this->manager->make($this->asset->getFilename())->encode();
}
return $this->response->header('content-type', $this->asset->getMimetype())->setContent($image);
}
示例15: process
/**
* Performs image processing
*
* @param ModelContract $model
* @param array $styleGuides
* @param string $path
*/
public function process(ModelContract &$model, array $styleGuides, $path)
{
// load styles
$styles = $this->getStyles($model, $styleGuides);
$originalClosure = array_get($styles, 'original', null);
// get Image object
$image = $this->imageManager->make($model->getSourceFile()->getFileInfo());
// apply original style
$original = $this->processStyle($model, $image, 'original', $originalClosure);
array_forget($styles, 'original');
// apply styles
foreach ($styles as $styleName => $closure) {
$this->processStyle($model, $original, $styleName, $closure);
}
}