tpmanc/yii2-imagick
Composer 安装命令:
composer require tpmanc/yii2-imagick
包简介
Yii 2 class for working with Imagick
README 文档
README
Yii 2 class for working with Imagick.
Install via Composer
Run the following command
$ composer require tpmanc/yii2-imagick "*"
or add
$ "tpmanc/yii2-imagick": "*"
to the require section of your composer.json file.
Original image:
Get size
$img = Imagick::open('./image.jpg'); $img->getWidth(); $img->getHeight();
Resize image
Imagick::open('./image.jpg')->resize(400, 300)->saveTo('./resized.jpg'); Imagick::open('./image.jpg')->resize(400, false)->saveTo('./resized.jpg');
Create thumbnail
Imagick::open('./image.jpg')->thumb(200, 200)->saveTo('./thumb.jpg');
Add border
$width = 5; $color = '#000' Imagick::open('./image.jpg')->border($width, $color)->saveTo('./result.jpg');
$width = 10; $color = '#A91AD4' Imagick::open('./image.jpg')->border($width, $color)->saveTo('./result.jpg');
Vertical and horizontal mirror image
// vertical Imagick::open('./image.jpg')->flip()->saveTo('./result.jpg'); // horizontal Imagick::open('./image.jpg')->flop()->saveTo('./result.jpg');
Crop
$xStart = 0; $yStart = 0; $xEnd = 150; $yEnd = 150; Imagick::open('./image.jpg')->crop($xStart, $yStart, $xEnd, $yEnd)->saveTo('./result.jpg');
Blur
$radius = 8; $delta = 5; Imagick::open('./image.jpg')->blur($radius, $delta)->saveTo('./result.jpg');
Watermark
Set watermark position
Use $xPosition and $yPosition to set watermark position.
$xPosition should be 'left', 'right' or 'center'; $yPosition should be 'top', 'bottom' or 'center'.
$xPosition = 'left'; $yPosition = 'top'; Imagick::open('./image.jpg')->watermark('./watermark.png'), $xPosition, $yPosition)->saveTo('./result.jpg');
$xPosition = 'right'; $yPosition = 'center'; Imagick::open('./image.jpg')->watermark('./watermark.png'), $xPosition, $yPosition)->saveTo('./result.jpg');
Set watermark size
Use $xSize and $ySize to set watermark size. Valid values:
-
Number:
$xSize = 100;,$ySize = 50 -
Percent of parent:
$xSize = '100%';,$ySize = '50%' -
'auto'to save proportion:$xSize = '100%';,$ySize = 'auto' -
false:$xSize = 100;,$ySize = false
$xPosition = 'center'; $yPosition = 'center'; $xSize = '100%'; $ySize = 'auto'; Imagick::open('./image.jpg')->watermark('./watermark.png'), $xPosition, $yPosition, $xSize, $ySize)->saveTo('./result.jpg');
$xPosition = 'center'; $yPosition = 'center'; $xSize = '100%'; $ySize = '100%'; Imagick::open('./image.jpg')->watermark('./watermark.png'), $xPosition, $yPosition, $xSize, $ySize)->saveTo('./result.jpg');
Set watermark offset
Use $xOffset and $yOffset to set offset from parent image border.
$xPosition = 'right'; $yPosition = 'bottom'; $xSize = false; $ySize = false; $xOffset = 50; $yOffset = 50; Imagick::open('./image.jpg')->watermark('./watermark.png'), $xPosition, $yPosition, $xSize, $ySize, $xOffset, $yOffset)->saveTo('./result.jpg');
tpmanc/yii2-imagick 适用场景与选型建议
tpmanc/yii2-imagick 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 175.56k 次下载、GitHub Stars 达 18, 最近一次更新时间为 2015 年 07 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「imagick」 「yii」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tpmanc/yii2-imagick 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tpmanc/yii2-imagick 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tpmanc/yii2-imagick 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A custom URL rule class for Yii 2 which allows to create translated URL rules
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
Stand-alone zoomify tile generator (format Zoomify) for use with OpenSeadragon, OpenLayers and various viewers.
Image manipulation library for Laravel 8 based on Imagine and inspired by Croppa for easy url based manipulation
Priveate for SkeekS CMS
Php library for converting and caching images to Webp .webp, JpegXr .jxr, Jpeg 2000 .jp2
统计信息
- 总下载量: 175.56k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 18
- 点击次数: 9
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2015-07-31