pyrsmk/imagix
最新稳定版本:0.6.5
Composer 安装命令:
composer require pyrsmk/imagix
包简介
The simple image effects library
README 文档
README
Imagix is a library, based on GD, that aims to simplify the use of effects on images. This project is born with two ideas in mind :
- we usually just want to apply some effects without headaches
- we sometimes do not have a full control on the hosting server and therefore cannot rely on other image manipulation PHP extensions than GD
Install
composer require pyrsmk/imagix
Instantiating
The simplest way to instantiate an image is with the Imagix\Factory class (it uses Exif PHP extension to guess which adapter to load) :
$imagix=Imagix\Factory::forge('path/to/your/image/file.jpg');
It detects automatically the image type and loads the relevant adapter to use. But, if needed (and because it uses more resources), you can instantiate an image adapter by yourself :
$adapter=new Imagix\Adapter\PNG('path/to/your/image/file.png'); $imagix=new Imagix($adapter);
Here's the available image adapters :
Imagix\Adapter\GIFImagix\Adapter\JPEGImagix\Adapter\PNG
Applying effects
A quick example :
// Convert image to grayscale $imagix->grayscale(); // Resize the image to a maximum of 600x400 by keeping the ratio $imagix->resize(600,400); // Add a black border of 3px around the image $imagix->border(3); // Save the image $imagix->save('mynewimage.jpg');
There's more than 30 sugar effects you can use. Some of them are only available when PHP has been compiled with the bundled version of GD. It's generally the case but not on Debian systems.
-
*: only available with the GD bundle -
#: the effect is resource-hungry -
[*] addition(
$color,$opacity=100) : add a color to the image; it takes an HTML color for the$colorparameter -
[*] blur(
$method=SELECTIVE) : blur the image; it supportsGAUSSIANandSELECTIVEblur methods -
border(
$thickness,$color='#000000',$sides=ALL) : draw a border around the image; support side constants areALL(by default),TOP,RIGHT,BOTTOM,LEFT -
[*] brightness(
$level) : adjust the brightness; the brightness level must be between-255and255(included) -
[#] channels(
$r,$g,$b) : make some adjustments on RGB channels; each channel takes one of these constants :NONE,RED,GREEN,BLUE,MINIMIZE,MAXIMIZE -
[*] contrast(
$level) : adjust the contrast of the image -
corner(
$size=10,$type=ROUNDED,$corners=ALL) : apply a mask to each corner of the image to make them rounded or truncated (per example); the$typeparamater supportsROUNDED,BEVELLEDandTRUNCATEDmethods; the$cornersparameter acceptsALL,TOPLEFT,TOPRIGHT,BOTTOMRIGHTandBOTTOMLEFTconstants -
crop(
$x,$y,$width,$height) : crop an image -
[#] duotone(
$r,$g,$b) : apply a duotone effect; the RGB parameters are an amount that will be added to the RGB channels of the image -
[*] edge() : apply an edge effect
-
[*] emboss(
$method=MATRIX) : emboss the image;MATRIXandFILTERmethods are supported -
enhance() : enhance an image
-
gamma(
$input,$output) : adjust the gamma correction -
[*] grayscale() : convert an image to grayscale
-
[#] hsla(
$h,$s,$l,$a) : modify the HSLA channels of an image -
[#] hsva(
$h,$s,$v,$a) : modify the HSVA channels of an image -
interlace() : interlace the image
-
line(
$x1,$y1,$x2,$y2,$thickness=1,$color='#000000') : draw a line on the image -
lines(
$direction=HORIZONTAL,$step=2,$thickness=1,$color='#000000') : draw several lines on the image; it supportsHORIZONTALandVERTICALconstants for the$directionparameter; the$stepparameter is the size in pixels where a new line should be drawed -
[#] mask(
$mask,$x,$y) : apply a mask on the image; the$maskparameter is a GD resource; the$xand$yparameters specify where the mask should be applied -
matrix(
$matrix,$color_offset) : apply a matrix to the image; for further informations read the documentation ofimageconvolution() -
merge(
$image,$method=NORMAL,$x1,$y1,$x2,$y2,$src_w,$src_h,$pct) : merge two images; please read theimagecopymerge()documentation to have further informations on how to set the parameters; the$methodparameter takes either theNORMALorGRAYSCALEconstant -
[*] negate() : negate the image
-
[#] noise(
$level=5) : add noise to the image -
[*] pixelate(
$block_size=2,$advanced=true) : pixelate the image -
ratio(
$w_ratio,$h_ratio,$position=CENTERED) : apply a ratio to the image; supportsCENTERED(by default),TOP,RIGHT,BOTTOMandLEFTconstants as position -
resize(
$width,$height,$keep_ratio=true) : resize the image; if$keep_ratioistrueit will consider the specified resolution as the maximum resolution to reach (explicitly, your image may not be of the size you specified); you can only pass a percent value for thewidthparameter to resize your image directly with a ratio -
[*] rotate(
$angle,$background='#FFFFFF') : rotate the image by the specified angle -
[#] scatter(
$level=1) : apply a scatter effect -
screen() : apply a screen effect
-
[*] sepia() : apply a sepia effect
-
[*] sharpen(
$method=MATRIX) : apply a sharpen effect; supported constant methods areMATRIX(by default) andFILTER -
shift() : shift the image
-
[*] smooth() : apply a smooth effect
-
truecolor() : convert the image to true colors
Advanced image handling
The API of Imagix\Image :
- getAdapter() : get the used adapter
- getWidth() : get the width of the image
- getHeight() : get the height of the image
- save(
$path,$options) : save the image
The API of all adapters :
- getResource() : get the GD resource of the image
- setResource(
$resource) : set the resource of the image - getPath() : get the path of the source image
- getContents() : get the image contents
- getMimetype() : get the MIME type
The save() method can take specific options for the image to save.
// For the JPEG adapter $imagix->save('image.jpg',array( // defaults to 80 'quality' => 95 )); // For the PNG adapter $imagix->save('image.jpg',array( // a value between 0 and 9 (by default) 'quality' => 7, // for a better understanding on PNG filters, take a look at : // https://stackoverflow.com/questions/3048382/in-php-imagepng-accepts-a-filter-parameter-how-do-these-filters-affect-the-f 'filters' => PNG_NO_FILTER ));
If you want to export an image to another format :
$png_adapter=new Imagix\Adapter\PNG('image.png'); $image=new Imagix\Image(new Imagix\Adapter\JPEG($png_adapter)); $image->save('image.jpg');
When processing a lot of images, we advise you to free allocated memory when you're done with one image :
imagedestroy($imagix->getAdapter()->getResource());
License
Imagix is released under the MIT license.
pyrsmk/imagix 适用场景与选型建议
pyrsmk/imagix 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 141 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 02 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「resize」 「crop」 「effect」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pyrsmk/imagix 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pyrsmk/imagix 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pyrsmk/imagix 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A bundle providing fields for image upload with jquery upload and image cropping with jcrop for symfony2
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.
Image cache
A image cropping field for kirby.
The lireincore/imgcache integration for the Yii2 framework
统计信息
- 总下载量: 141
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-02-04