jcupitt/vips
Composer 安装命令:
composer require jcupitt/vips
包简介
A high-level interface to the libvips image processing library.
关键字:
README 文档
README
php-vips is a binding for libvips 8.7
and later that runs on PHP 7.4 and later.
libvips is fast and needs little memory. The
vips-php-bench repository
tests php-vips against imagick and gd. On that test, and on my laptop,
php-vips is around four times faster than imagick and needs 10 times
less memory.
Programs that use libvips don't manipulate images directly, instead they create pipelines of image processing operations starting from a source image. When the pipe is connected to a destination, the whole pipeline executes at once and in parallel, streaming the image from source to destination in a set of small fragments.
Install
You need to install the libvips library. It's in the linux package managers, homebrew and MacPorts, and there are Windows binaries on the vips website. For example, on Debian:
sudo apt-get install --no-install-recommends libvips42
(--no-install-recommends stops Debian installing a lot of extra packages)
Or macOS:
brew install vips
You'll need to enable FFI in your
PHP, then add vips
to your composer.json:
"require": {
"jcupitt/vips" : "2.4.0"
}
php-vips does not yet support preloading, so you need to enable FFI globally. This has some security implications, since anyone who can run php on your server can use it to call any native library they have access to.
Of course if attackers are running their own PHP code on your webserver you are probably already toast, unfortunately.
Finally, on php 8.3 and later you need to disable stack overflow tests. php-vips executes FFI callbacks off the main thread and this confuses those checks, at least in php 8.3.0.
Add:
zend.max_allowed_stack_size=-1
To your php.ini.
Example
#!/usr/bin/env php <?php require __DIR__ . '/vendor/autoload.php'; use Jcupitt\Vips; // handy for Windows Vips\FFI::addLibraryPath("C:/vips-dev-8.16/bin"); // check libvips version echo 'libvips version: ' . Vips\Config::version() . PHP_EOL; // fast thumbnail generator $image = Vips\Image::thumbnail('somefile.jpg', 128); $image->writeToFile('tiny.jpg'); // load an image, get fields, process, save $image = Vips\Image::newFromFile($argv[1]); echo "width = $image->width\n"; $image = $image->invert(); $image->writeToFile($argv[2]);
Run with:
$ composer install
$ ./try1.php ~/pics/k2.jpg x.tif
See examples/. We have a complete set of formatted API
docs.
How it works
php-vips uses php-ffi to
call directly into the libvips binary. It introspects the library binary
and presents the methods it finds as members of the Image class.
This means that the API you see depends on the version of libvips that php-vips finds at runtime, and not on php-vips. php-vips documentation assumes you are using the latest stable version of the libvips library.
The previous php-vips version that relied on a binary extension and not on php-ffi is still available and supported in the 1.x branch.
Introduction to the API
Almost all methods return a new image as the result, so you can chain them. For example:
$new_image = $image->more(12)->ifthenelse(255, $image);
will make a mask of pixels greater than 12, then use the mask to set pixels to either 255 or the original image.
Note that libvips operators always make new images, they don't modify existing
images, so after the line above, $image is unchanged.
You can use long, double, array and image as parameters. For example:
$image = $image->add(2);
to add two to every band element, or:
$image = $image->add([1, 2, 3]);
to add 1 to the first band, 2 to the second and 3 to the third. Or:
$image = $image->add($image2);
to add two images. Or:
$image = $image->add([[1, 2, 3], [4, 5, 6]]);
To make a 3 x 2 image from the array, then add that image to the original.
Almost all methods can take an extra final argument: an array of options. For example:
$image->writeToFile("fred.jpg", ["Q" => 90]);
php-vips comes with API
docs.
To regenerate these from your sources, type:
$ vendor/bin/phpdoc
And look in docs/.
Unfortunatly, due to php-doc limitations, these do not list every option to every operation. For a full API description you need to see the main libvips documentation:
https://libvips.org/API/current
Test and install
$ composer install
$ composer test
$ vendor/bin/phpdoc
Regenerate auto docs
$ cd src
$ ../examples/generate_phpdoc.py
jcupitt/vips 适用场景与选型建议
jcupitt/vips 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.9M 次下载、GitHub Stars 达 705, 最近一次更新时间为 2016 年 09 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「image」 「processing」 「libvips」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jcupitt/vips 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jcupitt/vips 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jcupitt/vips 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
libvips adapter for imagine
libvips driver for Intervention Image
VIPS driver for Intervention Image.
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.
paywant api php client
统计信息
- 总下载量: 1.9M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 712
- 点击次数: 29
- 依赖项目数: 33
- 推荐数: 8
其他信息
- 授权协议: MIT
- 更新时间: 2016-09-21