takuya/php-imagick-cmd-wrapper
Composer 安装命令:
composer require takuya/php-imagick-cmd-wrapper
包简介
image magick command line call from php
README 文档
README
Image magick shell command wrapper for php
requirements
apt install imagemagick
Why using magick shell command from php?
Occasionally, a php-imagick (ext-imagick) is not available.
Some mod-php server are not supporting ext-imagck. but convert command is easy to install.
Imagick class ( in ext-imagick) is not documented in precisely.
Think, Can you tell how to use 'png:compression-filter' in ext-imagick ?. Perhaps you can't.
But, there are very many 'convert' samples in web. and we are trying to system('convert a.jpg b.png') calling with escaping shell arguments. What's a irritated.
So, we need convert command wrapper.
Installing from GitHub
repo=git@github.com:takuya/php-imagick-cmd-wrapper.git
composer config repositories.takuya/php-imagick-cmd-wrapper vcs $repo
composer require takuya/php-imagick-cmd-wrapper
Usage Sample
$f_in = 'DkzpJ1lUUAA84KP.jpg'; $width = 500; // convert $convert = new Convert(); $ret = $convert ->setInputFile( $f_in ) ->unsharp('10x5+0.7+0') ->sample($width) ->pointsize(30) ->fill('blue') ->strokewidth(1) ->stroke('gray80') ->font('DejaVu-Sans') ->annotate('+10+100','unsharp_sample') ->setOutputFile( 'jpeg:-' ) ->execute(); $image_bin = $ret[1]; file_put_contents('out.jpg',$image_bin)
Important Notice! Call Method Ordering.
Before Use, You should know that OPTIONS Ordering is VERY IMPORTANT.
The convert command is Very NAIVE for option order.
We must care about Arguments Ordering.
Sample1 ( vain , not working. )
(new Identify()) ->setInputFile('a.jpg') ->format('[%w,%h]') ->execute();
This result in identify a.jpg -format '[%w,%h]' , but no work.
Sample2 ( works fine. )
(new Identify()) ->setInputFile('a.jpg') ->format('[%w,%h]') ->execute();
This result in identify -format '[%w,%h]' a.jpg , it will work fine.
More Sample Usage
Convert JPEG to PNG.
$convert = ; (new Convert()) ->setInputile( 'a.jpg' ) ->setOutputFile( 'b.png' ) ->execute();
Using STDOUT - converting jpeg to png
$convert = ; $result = (new Convert()) ->setInputile( 'a.jpg' ) ->setOutputFile( 'png:-' ) ->execute(); $png_binary = $result[1];
Using STDIN - converting jpeg to png
$convert = ; $result = (new Convert()) ->setInputile( '-', file_get_contents('a.jpg') ) ->setOutputFile( 'png:-' ) ->execute(); $png_binary = $result[1];
Structure of return value
command result is array of 3 entries
$result = [ '0' => ' int / exit status code' , '1' => ' string / stdout from command' , '2' => ' string / stderr from command' , ];
Resize(sampling Algorithm) and UnSharp and Normalization
$ret = $convert ->setInputFile( $f_in ) ->sample('50%') ->unsharp('10x5+0.7+0') ->normalize() ->setOutputFile( 'jpeg:-' ) ->execute();
IDE Auto Completion.
Options(methods) are auto generated from Help doc from 'convert -h'.
So, in Some IDE, Auto completions will not work fine.
If it happens then add a path src/generated/ to your Project search PATH.
Developing notice.
This project uses auto generated php code, parsing converet -h.
If you want to re-generate class, execute these command in CLI.
composer run generate-class convert
composer run generate-class montage
composer run generate-class identify
composer run generate-class mogrify
I used these environment. wsl1 debian.
wsl --list -v
NAME STATE VERSION
* Debian Running 1
cat /etc/debian_version
10.10
imagemagick from debian(wsl)
convert -version
Version: ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib djvu fftw fontconfig freetype heic jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png tiff webp wmf x xml zlib
test results.
testing
composer install
./vendor/bin/phpunit
takuya/php-imagick-cmd-wrapper 适用场景与选型建议
takuya/php-imagick-cmd-wrapper 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 58 次下载、GitHub Stars 达 2, 最近一次更新时间为 2021 年 08 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「shell」 「convert」 「imagick」 「image-magick」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 takuya/php-imagick-cmd-wrapper 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 takuya/php-imagick-cmd-wrapper 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 takuya/php-imagick-cmd-wrapper 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provides a simple decimal/roman number converter
A library that provides a simple infrastructure to create your own converters and to perform any conversion you want
AMWSCAN (Antimalware Scanner) is a php antimalware/antivirus scanner console script written in php for scan your project. This can work on php projects and a lot of others platform.
Shell command module for PHP.
Stand-alone zoomify tile generator (format Zoomify) for use with OpenSeadragon, OpenLayers and various viewers.
PHP library for the MUMSYS project
统计信息
- 总下载量: 58
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2021-08-19