webino/webino-image-thumb
Composer 安装命令:
composer require webino/webino-image-thumb
包简介
Image Thumbnailer for Zend Framework 2
README 文档
README
Service that provides API to manipulate images.
- Powered by PHPThumb
- Demo webino-image-thumb.demo.webino.org
Features
- Resize, crop, pad, rotate, show and save images
- Create image reflection
- Crop whitespace
- Sharpen images
- Watermark
Setup
Following steps are necessary to get this module working, considering a zf2-skeleton or very similar application:
- Run:
php composer.phar require webino/webino-image-thumb:dev-develop - Add
WebinoImageThumbto the enabled modules list
Requirements
- PHP >= 5.6
- GD 2.0+
QuickStart
-
For example add following code into the controller action, assume example image:
// We encourage to use Dependency Injection instead of Service Locator $thumbnailer = $this->getServiceLocator()->get('WebinoImageThumb'); $imagePath = 'public/images/example.jpg'; $thumb = $thumbnailer->create($imagePath, $options = [], $plugins = []); $thumb->resize(100, 100); $thumb->show(); // or/and $thumb->save('public/images/resized.jpg');NOTE: If you don't know how to inject the WebinoImageThumb into action controller, check out
test/resources -
Use reflection plugin:
$reflection = $thumbnailer->createReflection(40, 40, 80, true, '#a4a4a4'); $thumb = $thumbnailer->create($imagePath, [], [$reflection]); -
Use whitespace cropper plugin:
$cropper = $thumbnailer->createWhitespaceCropper(); $thumb = $thumbnailer->create($imagePath, [], [$cropper]); -
Use sharpen plugin:
$sharpen = $thumbnailer->createSharpen(); $thumb = $thumbnailer->create($imagePath, [], [$sharpen]); -
Use watermark plugin:
$watermarkPath = 'public/images/my_watermark.png'; $watermarkThumb = $thumbnailer->create($watermarkPath); $watermark = $thumbnailer->createWatermark($watermarkThumb); $thumb = $thumbnailer->create($imagePath, [], [$watermark]);
Options
The options array allows you to customize the behavior of the library a bit. Some of these options are implementation-specific, and are noted as such. So, let's first go over what options are available to us:
| Option Name | Description | Default Value | Valid Values |
|---|---|---|---|
| resizeUp | Whether or not to scale an image up to the desired dimensions | false | true / false |
| jpegQuality | What quality to save jpeg files with (how much compression to use, 100 being none) | 100 | 1-100 |
| correctPermissions | Whether or not the library should attempt to correct file permissions. This will only work if you set up your PHP to allow chmod operations | false | true / false |
| preserveAlpha | Whether or not to preserve alpha transparency in PNG files | true | true / false |
| alphaMaskColor | What rgb color should be used for the alpha mask | [255, 255, 255] |
[0-255, 0-255, 0-255] |
| preserveTransparency | Whether or not to preserve transparency in GIF files | true | true / false |
| transparencyMaskColor | What rgb color should be used for the transparency mask | [255, 255, 255] |
[0-255, 0-255, 0-255] |
| interlace | When the interlace option equals true or false call imageinterlace | null |
true / false |
Functions
adaptiveResize($width, $height)adaptiveResizePercent($width, $height, $percent = 50)adaptiveResizeQuadrant($width, $height, $quadrant = 'T|B|C|L|R')crop($startX, $startY, $cropWidth, $cropHeight)cropFromCenter($cropWidth, $cropHeight = null)pad($width, $height, $color = [255, 255, 255])resize($maxWidth, $maxHeight)resizePercent($percent)rotateImage($direction = 'CW|CCW')rotateImageNDegrees($degrees)save($fileName, $format = 'GIF|JPG|PNG')show($rawData = false)
Getters / Setters
getCurrentDimensions()getFileName()getFormat()getIsRemoteImage()getMaxHeight()getMaxWidth()getNewDimensions()getOldImage()getOptions()getPercent()getWorkingImage()setCurrentDimensions($currentDimensions)setFileName($fileName)setFormat($format)setMaxHeight($maxHeight)setMaxWidth($maxWidth)setNewDimensions($newDimensions)setOldImage($oldImage)setOptions($options)setPercent($percent)setWorkingImage($workingImage)
Reflection plugin
-
createReflection($percent, $reflection, $white, $border, $borderColor)$percent- What percentage of the image to create the reflection from.$reflection- What percentage of the image height should the reflection height be.$white- How transparent (using white as the background) the reflection should be, as a percent.$border- Whether a border should be drawn around the original image.$borderColor- The hex value of the color you would like your border to be.
Whitespace Cropper plugin
-
createWhitespaceCropper($border, $color)$margin- What pixels of a margin should be around the original image.$color- The hex value of the color you would like to crop.
Watermark plugin
-
createWatermark(PHPThumb $watermarkThumb, $position = [0, 0], $scale = .5)$watermarkThumb- Watermark image from watermark file.$position- Position of watermark, center by default:[0, 0]- center[-1, -1]- left bottom[-1, 1]- left top[1, 1]- right top[1, -1]- right bottom
$scale- Scale of the watermark relative to the image.
Changelog
3.0.0 [UNRELEASED]
- Removed deprecated plugin classes
2.1.0
- Requires webino/thumbnailer replacing masterexploder/PHPThumb
- Deprecated plugin classes, moved to webino/thumbnailer package
2.0.0
- PHP >= 5.6
- Requires PHPThumb 2.0 via composer
- Added Whitespace Cropper plugin
- Added Sharpen plugin
- Removed ZF autoloader support
- Added Watermark plugin
- Added ImageThumbAwareInterface & Trait
1.0.0
- Initial release
Development
We will appreciate any contributions on development of this module.
Learn How to develop Webino modules
Addendum
Most of the documentation is taken from the PHPThumb wiki.
Please, if you are interested in this Zend Framework module report any issues and don't hesitate to contribute.
webino/webino-image-thumb 适用场景与选型建议
webino/webino-image-thumb 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 80.42k 次下载、GitHub Stars 达 40, 最近一次更新时间为 2012 年 11 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「image」 「zend」 「zf2」 「webino」 「thumb」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 webino/webino-image-thumb 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 webino/webino-image-thumb 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 webino/webino-image-thumb 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
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.
Polyfill for mb_ereg(), mb_eregi(), mb_ereg_match(), and mb_ereg_replace*() functions; primary use case is for mbstring on Windows 7.4+
Zend Framework 1 Http package
Zend Framework 1 Soap package
统计信息
- 总下载量: 80.42k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 43
- 点击次数: 0
- 依赖项目数: 4
- 推荐数: 2
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2012-11-03