saad/image
Composer 安装命令:
composer require saad/image
包简介
This Package to deal with images crop, resize, write text, integrate with Eloquent Model to get and save inmages and creating thumbnails'
README 文档
README
Install
You can pull in the package via composer:
$ composer require saad/image
Register Package Service Provider for Laravel
Laravel 5.5The package will automatically register itself.
Laravel < 5.5
add the following to your providers in config\app.php
'providers' => [ ..... Saad\Image\ImageServiceProvider::class, ]
Publish package aconfiguration and assets
php artisan vendor:publish --provider="Saad\Image\ImageServiceProvider"
use
to use Core Image Library
<?php use Saad\Image\Image; $image = new Image( $image_src ); // you can then manipulate image // Set Save Output Format $image->setOutputFormat('png'); // Set Save Options $image->setSaveOptions('image_name', 'Save_Path'); // Create Thumbnail $image->createThumbnail(100, 100); // Save and destroy resource from memory $image->export(); // Save and keep resource to continue manipulating same resource $image->export(true); // Get Image as data-url string $image->embed();
Laravel Eloquent Traits
this package ships with two traits to make it easy to save images on eloquent models
EloquentImageSaverTrait used to dynamically save uploaded images and creating thumbnails
EloquentPublicImageTrait used to get public url for saved images and it's created thumbnails
Full Example
assume we have a user Model which has image column to store user profile image
<?php .... use Saad\Image\Traits\EloquentImageSaverTrait; use Saad\Image\Traits\EloquentPublicImageTrait; class User extends Model { use EloquentImageSaverTrait, EloquentPublicImageTrait; protected static $profile_image_sizes = [ [ 256, 256 ], // Default image size [ 100, 100 ], // Thumbnail [ 46, 46 ], // Thumbnail [ 26, 26 ], // Thumbnail ]; /** * Get Image * @return String Image Url */ public function getImage() { return $this->getImagePublicLink( 'image', 'images/profiles/' ); } /** * Get Image Thumbnail * @param String $size Thumbnail size in format '46x46' * @return String Image Thumbnail Url */ public function getImageThumb( $size ) { return $this->getImagePublicLink( 'image', 'images/profiles/thumb/', $size ); } /** * Mutator To Save and Set Image * * Save Image and create thumbnails, and set image name attribute to model */ public function setImageAttribute( $file ) { $path = public_path( 'images/profiles/' ); if($file instanceof \Illuminate\Http\UploadedFile) { $this->attributes['image'] = $this->saveImage( $file, $path, null, static::$profile_image_sizes, function( $object, $save_name ) use($path){ /** * Delete Old Images */ $this->deleteOldFor( $object->image, $path ); } ); } else { $file = realpath(public_path('/images/temp/'.$file)); $this->attributes['image'] = $this->saveLocalImage( $file, $path, null, static::$profile_image_sizes, function( $object, $save_name ) use($path){ /** * Delete Old Images */ $this->deleteOldFor( $object->image, $path ); }); } } }
saad/image 适用场景与选型建议
saad/image 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.98k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 12 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 saad/image 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 saad/image 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 saad/image 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
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.
Yii2 prettyPhoto image galary widget uses Lightbox view control jquery.prettyphoto.js
Alfabank REST API integration
An image upload package which provides lot of functions such as upload, resize, crop, rotate, delete.
统计信息
- 总下载量: 6.98k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-12-02