mindshaker/image-upload
Composer 安装命令:
composer require mindshaker/image-upload
包简介
Laravel Image Upload
README 文档
README
This package makes image upload easy. It uses Intervention Image under the hood.
Installation
Require this package, with Composer, in the root directory of your project.
$ composer require mindshaker/image-upload
Configuration
There are some default configurations
return [ 'public_path' => 'uploads', 'random_name' => true, ];
You can change this values by publishing this configuration file
$ php artisan vendor:publish --provider="Mindshaker\\ImageUpload\\ImageUploadServiceProvider"
If you want to make your images private (blocked by auth for example), you'll need to add a new disk in config/filesystems.php and put this in the disks array
'private' => [ 'driver' => 'local', 'root' => storage_path('app/upload_folder'), 'url' => env('APP_URL') . '/storage', 'visibility' => 'private', 'throw' => false, ],
Usage
There are only a few methods, you can call the upload method to upload a image that will be edited to the given dimensions or cropped. The image will be saved to the public_path set in the configurations and be given a random name or the name of the original file.
The upload function returns the image name with additional path if set (see bellow)
use Mindshaker\ImageUpload\Facades\ImageUpload; ImageUpload::upload($image, $width = null, $height = null, $crop = false, $private = false);
To add an additional path
ImageUpload::path("additional_path");
To give specific name to the uploaded file, if set it will ignore the configuration random_name
ImageUpload::name("image_name");
To define the format of the image uploaded (e.g. png, jpg, webp, etc..)
ImageUpload::format("jpg");
To define the quality of the image, default 75.
ImageUpload::quality(75);
You can delete images by calling the method delete($image, $private = false) where $image is the name returned from the upload() method
$image_name = ImageUpload::upload($image, 1920); ImageUpload::delete($image_name);
Basic Examples
use Mindshaker\ImageUpload\Facades\ImageUpload; $image = $request->file('image'); //Simple upload ($width or $height needs to be specified) //It will resize the image to 1920px. It won't upscale ImageUpload::upload($image, 1920); //Crop the image to the given dimensions ImageUpload::upload($image, 512, 512, true); //Change the format of the image ImageUpload::format("webp")->upload($image, 1920); //Add aditional path and change name ImageUpload::path("posts/{id}")->name("post_name")->format("webp")->upload($image, 1920, null); //returns something like "posts/1/post_name.webp"
Adavanced Usage
If you want more than just resizing and cropping the images, you can call the method manager() and edit the image like it's an Intervention Image. This is a substitute to the upload method, all the other methods still work (Like path(), name() and format()). After editing, to upload the image you can call the method save() to upload the image to the specified path and format.
ImageUpload::manager($image);
Example
use Mindshaker\ImageUpload\Facades\ImageUpload; $image = $request->file('image'); ImageUpload::manager($image)->pad(512, 512, 'ccc')->format("png")->save();
mindshaker/image-upload 适用场景与选型建议
mindshaker/image-upload 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 103 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 02 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「upload」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mindshaker/image-upload 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mindshaker/image-upload 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mindshaker/image-upload 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The file manager intended for using Laravel with CKEditor / TinyMCE / Colorbox
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
Laravel Media Popup to upload/view the files
Yii2 prettyPhoto image galary widget uses Lightbox view control jquery.prettyphoto.js
统计信息
- 总下载量: 103
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2024-02-28