lireincore/imgcache
Composer 安装命令:
composer require lireincore/imgcache
包简介
Image cache
README 文档
README
About
Adds caching capabilities to the package lireincore/image
Also, you can use lireincore/yii2-imgcache extension that integrates this package with Yii2 framework.
And, you can use lireincore/LireinCoreImgCacheBundle bundle that integrates this package with Symfony framework.
Install
Add the "lireincore/imgcache": "^0.6" package to your require section in the composer.json file
or
$ php composer.phar require lireincore/imgcache
Usage
use LireinCore\ImgCache\ImgCache; $config = [ // graphic library for all presets: imagick, gd, gmagick // (by default, tries to use: imagick->gd->gmagick) 'driver' => 'gmagick', // original images source directory for all presets 'srcdir' => '/path/to/my/project/uploads', // thumbs destination directory for all presets (required) // (to access the thumbs from the web they should be in a directory accessible from the web) 'destdir' => '/path/to/my/project/www/thumbs', // web directory for all presets 'webdir' => '/path/to/my/project/www', // base url for all presets 'baseurl' => 'https://www.mysite.com', // quality of save jpeg images for all presets: 0-100 (default: 75) 'jpeg_quality' => 80, // compression level of save png images for all presets: 0-9 (default: 7) 'png_compression_level' => 8, // compression filter of save png images for all presets: 0-9 (default: 5) 'png_compression_filter' => 6, // formats convert map for all presets // supported formats for destination images: jpeg, png, gif, wbmp, xbm // (default: ['jpeg' => 'jpeg', 'png' => 'png', 'gif' => 'gif', 'wbmp' => 'wbmp', 'xbm' => 'xbm', // '*' => 'png']) 'convert_map' => [ // source format => destination format 'gif,wbmp' => 'png', // gif and wbmp to png '*' => 'jpeg' // all others to jpeg ], // plug for all presets (used if original image is not available) 'plug' => [ // absolute path to plug 'path' => '/path/to/my/project/assets/plug.png', // apply preset effects and postprocessors to plug? (default: false) 'process' => true, ], // define custom image class for all presets (which implements \LireinCore\Image\Manipulator interface) // (default: \LireinCore\Image\Manipulators\Imagine) 'image_class' => '\Foo\Bar\MyImageClass', // register custom effects or override default effects // (default effects: crop, cover, resize, scale_up, scale_down, scale, rotate, overlay, // flip, fit, blur, gamma, grayscale, negative, text) 'effects_map' => [ // effect => class (which implements \LireinCore\Image\Effect interface) 'myeffect1' => '\Foo\Bar\MyEffect1', 'myeffect2' => '\Foo\Bar\MyEffect2' ], // register custom postprocessors or override default postprocessors // (default postprocessors: jpegoptim, optipng, pngquant) 'postprocessors_map' => [ // postprocessor => class (which implements \LireinCore\Image\PostProcessor interface) 'my_postprocessor1' => '\Foo\Bar\MyPostProcessor1', 'my_postprocessor2' => '\Foo\Bar\MyPostProcessor2' ], // postprocessors list 'postprocessors' => [ [ // postprocessor type 'type' => 'jpegoptim', // postprocessor params 'params' => [ 'path' => '/path/to/jpegoptim', // custom path to postprocessor binary // (default: '/usr/bin/jpegoptim') 'quality' => 75, // for example: 0-100, 0 - worst | 100 - best // (default: 85) 'strip_all' => false, // remove all metadata (Comments, Exif, IPTC, ICC, XMP) // (default: true) 'progressive' => false // convert to progressive jpeg (default: true) ] ], [ // postprocessor type 'type' => 'optipng', // postprocessor params 'params' => [ 'path' => '/path/to/optipng', // custom path to postprocessor binary // (default: '/usr/bin/optipng') 'level' => 5, // for example: 0-7, 0 - max compression speed | // 7 - max compression size (default: 2) 'strip_all' => false // remove all metadata (default: true) ] ] ], // presets list 'presets' => [ // preset 'origin' 'origin' => [ // effects list 'effects' => [ [ // effect type 'type' => 'overlay', // effect params 'params' => [ 'path' => '/path/to/watermark.png', // path to overlay 'opacity' => 80, // overlay opacity, for example: 0-100, // 0 - fully transparent | 100 - not transparent // (default: 100) (not supported in gmagick) 'offset_x' => 'right', // overlay horizontal offset, for example: 100 | 20% | // center | left | right (default: right) 'offset_y' => 'bottom', // overlay vertical offset, for example: 100 | 20% | // center | top | bottom (default: bottom) 'width' => '50%', // overlay width, for example: 100 | 20% - change // overlay image width // (% - relative to the background image) // (default: original size) 'height' => '50%' // overlay height, for example: 100 | 20% - change // overlay image height // (% - relative to the background image) // (default: original size) ] ], ], // you can override certain options for this preset // graphic library for preset 'origin' 'driver' => 'gd', // original images source directory for preset 'origin' 'srcdir' => '/path/to/my/project/backend/uploads', // thumbs destination directory for preset 'origin' // (to access the thumbs from the web they should be in a directory accessible from the web) 'destdir' => '/path/to/my/project/backend/www/thumbs', // web directory for preset 'origin' 'webdir' => '/path/to/my/project/backend/www', // base url for preset 'origin' 'baseurl' => 'https://admin.mysite.com', // quality of save jpeg images for preset 'origin' 'jpeg_quality' => 100, // compression level of save png images for preset 'origin' 'png_compression_level' => 9, // compression filter of save png images for preset 'origin' 'png_compression_filter' => 9, // plug for preset 'origin' (used if original image is not available) 'plug' => [ 'path' => '/path/to/my/project/backend/assets/plug_origin.png', ], // define custom image class for preset 'origin' // (which implements \LireinCore\Image\Manipulator interface) 'image_class' => '\Foo\Bar\MyOriginImage', // postprocessors list for preset 'origin' 'postprocessors' => [ [ // postprocessor type 'type' => 'pngquant', // postprocessor params 'params' => [ 'path' => '/path/to/pngquant', // custom path to postprocessor binary // (default: '/usr/bin/pngquant') 'quality' => 75, // for example: 0-100, 0 - worst | 100 - best // (default: 85) ] ] ], ], // preset 'content_preview' 'content_preview' => [ 'effects' => [ // first effect [ 'type' => 'scale_up', 'params' => [ 'max_width' => '500', // for example: 100 | 20% (default: auto) 'max_height' => '500', // for example: 100 | 20% (default: auto) 'allow_increase' => true // increase if image is less (default: false) ] ], // second effect [ 'type' => 'crop', 'params' => [ 'offset_x' => '50%', // for example: 100 | 20% | center | left | right // (default: left) 'offset_y' => '50%', // for example: 100 | 20% | center | top | bottom // (default: top) 'width' => '50%', // for example: 100 | 20% (default: auto) 'height' => '50%' // for example: 100 | 20% (default: auto) ] ], // third effect [ 'type' => 'gamma', 'params' => [ 'correction' => 0.8 // gamma correction (0.0-1.0) ] ], // fourth effect [ 'type' => 'blur', 'params' => [ 'sigma' => 3 // standard deviation ] ] ], // formats convert map for preset 'content', extend convert map for all presets 'convert_map' => [ 'xbm' => 'png', // xbm to png 'gif' => 'jpeg' ], 'plug' => [ // url to get the plug from a third-party service 'url' => 'http://placehold.it/100x100' ], ], // preset 'test' 'test' => [ 'effects' => [ [ 'type' => 'grayscale', ], [ 'type' => 'fit', 'params' => [ 'offset_x' => 'center', // for example: 100 | 20% | center | left | right // (default: center) 'offset_y' => 'center', // for example: 100 | 20% | center | top | bottom // (default: center) 'width' => '200', // for example: 100 | 20% (default: auto) 'height' => '90', // for example: 100 | 20% (default: auto) 'bgcolor' => '#f00', // background color, for example: '#fff' or '#ffffff' - // hex | '50,50,50' - rgb | '50,50,50,50' - cmyk // (default: #fff) 'bgtransparency' => 50, // background transparency, for example: 0-100, // 0 - not transparent | 100 - fully transparent // (default: 0) (not supported in gmagick) 'allow_increase' => true // increase if image is less (default: false) ] ] [ 'type' => 'text', 'params' => [ 'text' => 'Hello word!', // text for writing 'font' => '/path/to/font', // font name or absolute path to the font file, // for example: Verdana (default: Times New Roman) 'offset_x' => '5%', // for example: 100 | 20% (default: 0) 'offset_y' => '10', // for example: 100 | 20% (default: 0) 'size' => 14, // font size, for example: 14 (default: 12) 'color' => '#000', // font color, for example: '#fff' or '#ffffff' - hex | // '50,50,50' - rgb | '50,50,50,50' - cmyk // (default: #fff) 'opacity' => 50, // font opacity, for example: 0-100, // 0 - fully transparent | 100 - not transparent // (default: 100) 'angle' => 30, // in degrees, for example: 90 (default: 0) 'width' => '90%', // for example: 100 | 20% - text box width // (% - relative to the background image) // (default: none) ] ] ], ], // preset 'test2' 'test2' => [ 'effects' => [ [ 'type' => 'negative' ], [ 'type' => 'flip', 'params' => [ 'mode' => 'horizontal' // for example: vertical | horizontal | full ] ], [ 'type' => 'resize', 'params' => [ 'width' => '100', // 100 | 20% (default: auto) 'height' => '100' // 100 | 20% (default: auto) ] ], [ 'type' => 'rotate', 'params' => [ 'angle' => 90, // angle in degrees 'bgcolor' => '#f00', // background color, for example: '#fff' or '#ffffff' - // hex | '50,50,50' - rgb | '50,50,50,50' - cmyk // (default: #fff) 'bgtransparency' => 70 // background transparency, for example: 0-100, // 0 - not transparent | 100 - fully transparent // (default: 0) (not supported in gmagick) ] ], [ 'type' => 'scale', 'params' => [ 'ratio' => '200%', // (for example: 0.5 | 50%) ] ], ], ], // preset 'test3' 'test3' => [ 'effects' => [ [ 'type' => 'cover', 'params' => [ 'offset_x' => 'left', // for example: 100 | 20% | center | left | right // (default: center) 'offset_y' => 'top', // for example: 100 | 20% | center | top | bottom // (default: center) 'width' => '200', // for example: 100 | 20% (default: auto) 'height' => '90', // for example: 100 | 20% (default: auto) ] ] ], ], ], ]; $imgcache = new ImgCache($config); // get thumb path for image '{srcdir}/user/image.jpg' (preset 'origin') $thumbPath = $imgcache->path('user/image.jpg', 'origin'); // $thumbPath === '{destdir}/presets/origin/user/image.jpg' // if the source image is not found // $thumbPath === '{destdir}/plugs/origin/plug_origin.png' // get thumb relative url for image '{srcdir}/blog/image.jpg' (preset 'content_preview') $thumbRelUrl = $imgcache->url('blog/image.jpg', 'content_preview'); // $thumbRelUrl === '/thumbs/presets/content_preview/blog/image.jpg' // get thumb absolute url for image '{srcdir}/news/image.jpg' (preset 'test') $thumbAbsUrl = $imgcache->url('news/image.jpg', 'test', true); // $thumbAbsUrl === '{baseurl}/thumbs/presets/test/news/image.jpg' // clear preset thumbs $imgcache->clearCache('presetName'); // clear all presets thumbs $imgcache->clearCache();
License
This project is licensed under the MIT License - see the License File file for details
lireincore/imgcache 适用场景与选型建议
lireincore/imgcache 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.1k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2016 年 10 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「cache」 「resize」 「thumb」 「effect」 「preset」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lireincore/imgcache 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lireincore/imgcache 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lireincore/imgcache 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
repository php library
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.
Laravel 5 - Repositories to the database layer
The lireincore/imgcache integration for the Yii2 framework
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
统计信息
- 总下载量: 3.1k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 8
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-10-20