regulus/upstream
Composer 安装命令:
composer require regulus/upstream
包简介
A simple composer package for Laravel 5 that assists with file uploads and image resizing/cropping.
README 文档
README
A simple composer package for Laravel 5 that assists in file uploads and image resizing/cropping.
Installation
To install Upstream, make sure regulus/upstream has been added to Laravel 5's composer.json file.
"require": {
"regulus/upstream": "0.6.*"
},
Then run php composer.phar update from the command line. Composer will install the Upstream package. Now, all you have to do is register the service provider and set up Upstream's alias in config/app.php. Add this to the providers array:
Regulus\Upstream\UpstreamServiceProvider::class,
And add this to the aliases array:
'Upstream' => Regulus\Upstream\Facade::class,
Finally, run php artisan vendor:publish to publish the config file and language file.
Uploading Files
$config = [
'path' => 'uploads/pdfs', // the path to upload to
'field' => 'file', // name of field (use "fields" for an array with multiple fields)
'filename' => 'temp', // the basename of the file (extension will be added automatically)
'fileTypes' => ['png', 'jpg'], // the file types to allow
'createDirectory' => true, // automatically creates directory if it doesn't exist
'overwrite' => true, // whether or not to overwrite existing file of the same name
'maxFileSize' => '5MB', // the maximum filesize of file to be uploaded
];
$upstream = Upstream::make($config);
$result = $upstream->upload();
Note: Special
filenamestrings are available including[LOWERCASE],[UNDERSCORED],[LOWERCASE-UNDERSCORED],[DASHED],[LOWERCASE-DASHED], and[RANDOM]. The former five are used to make formatting adjustments to the original filename. The latter can be used to set the filename to a random string (along with its original extension).
Resizing Images and Creating Thumbnails
$config = [
'path' => 'uploads/images',
'fields' => ['picture', 'picture2'],
'filename' => 'temp',
'fileTypes' => 'images',
'createDirectory' => true,
'overwrite' => true,
'maxFileSize' => '5MB',
'imageResize' => true,
'imageResizeQuality' => 60,
'imageCrop' => true,
'imageDimensions' => [
'w' => 720, // image width
'h' => 360, // image height
'tw' => 180, // thumbnail image width
'th' => 180, // thumbnail image height
],
];
$upstream = Upstream::make($config);
$result = $upstream->upload();
An entire set of configuration array is available in the config file at src/config/config.php. You may crop images after they have been uploaded with the following:
$config = [
'path' => 'uploads/images',
'filename' => 'temp-'.$id.'.jpg',
'newFilename' => $id.'.jpg',
'createDirectory' => true,
'overwrite' => true,
'imageThumb' => true,
'imageDimensions' => [
'w' => 260, // image width
'h' => 260, // image height
'tw' => 120, // thumbnail image width
'th' => 120, // thumbnail image height
],
'cropPosition' => [
'x' => $input['x'], // X position
'y' => $input['y'], // Y position
'w' => $input['width'], // width of cropped area
'h' => $input['height'], // height of cropped area
],
];
$result = Upstream::cropImage($config);
You may use a JavaScript image cropper such as Cropper to set the cropPosition. If you leave cropPosition null or unset, the image will first be scaled to 140% of the target dimensions and then cropped from the center.
regulus/upstream 适用场景与选型建议
regulus/upstream 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.55k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2014 年 10 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 regulus/upstream 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 regulus/upstream 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4.55k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-10-02