vinterskogen/laravel-uploaded-image 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vinterskogen/laravel-uploaded-image

Composer 安装命令:

composer require vinterskogen/laravel-uploaded-image

包简介

Gracefully deal with resizing, cropping and scaling uploaded images in Laravel apps

README 文档

README

Build Status StyleCI Latest Stable Version

Gracefully deal with resizing, cropping and scaling uploaded images in Laravel apps.

About

This package allows you to retrieve an uploaded image object from request, apply manipulations over the image content and then place the result to file storage in a few lines of code.

Under the hood this package is using Intervention Image - a PHP image handling and manipulation library.

Installation

Install via Composer:

composer require vinterskogen/laravel-uploaded-image

Check the Installation page for full information about package requirements and notes.

Usage

For example your app has a controller that handles the users' avatars uploads and saves the avatar images to file storage. You want that avatars to fit to 250x150 pixels and to be encoded into PNG format.

This can be done as easy as:

$request->image('avatar')
        ->fit(250, 150)
        ->encode('png')
        ->store('images/users/avatars', 'public');

The $request object now have an image method, that works just like the file method - retrieves an image file from the input and returns it as an instance of Vinterskogen\UploadedImage\Uploadedimage class.

This class extends the Laravel's Illuminate\Http\UploadedFile and implements a number of helpful image handling methods.

Note: to be sure the file you are going to handle like an image is actually an image file, you have to apply form request validation constraints on your input (if you haven't done that yet, of course).

Image handling methods

The list of public image handling methods that are available on Uploadedimage instance:

Fit

fit(int $width, int $height) – resize and crop the uploaded image to fit given width and height, keeping aspect ratio.

fitSquare(int $size) – resize and crop the uploaded image to fit a square with given side size, keeping aspect ratio.

Crop

crop(int $width, int $height, int $x = null, int $y = null) – crop uploaded image to given width and height.

Encode

encode(string $format, int $quality = null) – encode uploaded image in given format and quality.

Scale

scale(int|float $percentage) – scale the uploaded image size using given percentage.

Resize to width

resizeToWidth(int $width) – resize the uploaded image to new width, constraining aspect ratio.

Resize to height

resizeToHeight(int $height) – resize the uploaded image to new height, constraining aspect ratio.

Height

height() – get height of uploaded image (in pixels).

Width

width() – get width of uploaded image (in pixels).

License

The MIT license. See the accompanying LICENSE.md file.

Credit

Vinter Skogen, 2017-2022

统计信息

  • 总下载量: 161
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 13
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-09-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固