kujjs/resize-image
Composer 安装命令:
composer require kujjs/resize-image
包简介
Resize images with predefined sizes
README 文档
README
Based on anakadote/laravel-5-image-manager.
Resize images with predefined sizes in config / imageManager.php
Attention!!!!!!!!!!!!
important changes were made in how to obtain the cropped images, please read the new documentation.
If you don't want to replace the changes but want to use Auto-Discovery you can use version 5.5.0
Install
Edit your project's composer.json
"require": { "anakadote/laravel-5-image-manager": "dev-master", "kujjs/resize-image": "^0.5.5.1" }
Add the service provider. config/app.php
'providers' => [ kujjs\imageManager\imageManagerServiceProvider::class, // optional, you can use Auto-Discovery Anakadote\ImageManager\ImageManagerServiceProvider::class, ];
If not use Auto-Discovery your add next alias in config/app.php
'aliases' => [ ... 'Image' => 'kujjs\imageManager\Facades\ImageManager', ];
And run the following command
$ php artisan vendor:publish
Usage
Set sizes in config/imageManager.php
'sizes' => [ 'thumbnail' => [ 'width' => 120, 'height' => 120, 'mode' => 'crop', || fit || fit-x || fit-y 'quality' => 90 ] ];
| Property | Description | |
|---|---|---|
width |
required | The width of the generated image in pixels. |
height |
required | The height of the generated image in pixels. |
mode |
required | Defines the way the image will be transformed. See the table below for accepted modes |
quality |
required | The quality that will have the final image. range 0-100 |
| Mode | Description |
|---|---|
crop |
Will smart crop an image to make it fit the desired dimensions. It will cut content of the image off the top/bottom and sides if required to preserve the aspect ratio. |
fit |
Fit while maintaining aspect ratio |
fit-x |
Fit to the given width while maintaining aspect ratio |
fit-y |
Fit to the given height while maintaining aspect ratio |
Image::make($file , $size='thumbnail'))
{{ Image::make(public_path('img/image.jpg'),'thumbnail') }}
OR
{{ Image::make(public_path('img/image.jpg')) }}
Return
img/120-120/crop/image.jpg
| Property | Description | |
|---|---|---|
File |
required (string) | The fully qualified name of image file. The file must reside in your app's public directory. You'll need to grant write access by the web server to the public directory and its children |
Size Name |
(optional) (string) | The name of the size that is defined in config/imageManager.php. |
get full url
toUrl()
{{ Image::make(public_path('img/image.jpg'),'thumbnail')->toUrl() }}
return
http://mysite.dev/img/120-120/crop/image.jpg
Get tag img
toHtml( $attributes = [] )
{!! Image::make(public_path('img/image.jpg'),'thumbnail')->toHtml() !!}
Return
<img src="http://mysite.dev/img/120-120/crop/image.jpg">
Or
{!! Image::make(public_path('img/image.jpg'),'thumbnail')->toHtml(['class'=>'my-class','alt'=>'my alt','title'=>'my title', 'attributes'=>'values']) !!}
Return
<img src="http://mysite.dev/img/120-120/crop/image.jpg" "alt"="my alt" "title"="my title" "class"="my-class" "attributes"="values">
| Property | Description | |
|---|---|---|
attributes |
optional (array) | Attributes html you can inset in the tag img |
Remove
Image::delete($file)
remove image with all size declarade in config/imageManager.php
Image::delete(public_path('img/image.jpg'))
License
The MIT License (MIT). Please see License File for more information.
kujjs/resize-image 适用场景与选型建议
kujjs/resize-image 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.46k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 08 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「images」 「resize」 「laravel」 「kujjs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kujjs/resize-image 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kujjs/resize-image 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kujjs/resize-image 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova field for distribute your images as array of object.
Pexels API Client for www.pexels.com
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
Image cache
The lireincore/imgcache integration for the Yii2 framework
Convert and serve jpeg/png to webp with PHP (if at all possible)
统计信息
- 总下载量: 1.46k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-08-08