{"id":13700136,"url":"https://github.com/libvips/php-vips","last_synced_at":"2025-12-24T04:27:06.229Z","repository":{"id":40523895,"uuid":"66077617","full_name":"libvips/php-vips","owner":"libvips","description":"php binding for libvips","archived":false,"fork":false,"pushed_at":"2025-04-04T17:11:33.000Z","size":12381,"stargazers_count":653,"open_issues_count":8,"forks_count":26,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-04-26T20:02:33.442Z","etag":null,"topics":["libvips","php","php-bindings","php-extension"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/libvips.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2016-08-19T11:27:43.000Z","updated_at":"2025-04-25T08:44:33.000Z","dependencies_parsed_at":"2025-04-26T20:01:36.039Z","dependency_job_id":"ed713863-ea6b-43f6-9e87-be8063539a9c","html_url":"https://github.com/libvips/php-vips","commit_stats":{"total_commits":303,"total_committers":9,"mean_commits":"33.666666666666664","dds":"0.20132013201320131","last_synced_commit":"69c343e0bc7bac6dc82f4f16f985d8d6a15eb05a"},"previous_names":["jcupitt/php-vips"],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libvips%2Fphp-vips","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libvips%2Fphp-vips/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libvips%2Fphp-vips/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libvips%2Fphp-vips/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libvips","download_url":"https://codeload.github.com/libvips/php-vips/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251112795,"owners_count":21538164,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["libvips","php","php-bindings","php-extension"],"created_at":"2024-08-02T20:00:48.945Z","updated_at":"2025-12-24T04:27:06.224Z","avatar_url":"https://github.com/libvips.png","language":"PHP","funding_links":[],"categories":["图片处理"],"sub_categories":[],"readme":"# PHP binding for libvips \n\n[![CI](https://github.com/libvips/php-vips/workflows/CI/badge.svg)](https://github.com/libvips/php-vips/actions)\n\n`php-vips` is a binding for [libvips](https://github.com/libvips/libvips) 8.7\nand later that runs on PHP 7.4 and later.\n\nlibvips is fast and needs little memory. The\n[`vips-php-bench`](https://github.com/jcupitt/php-vips-bench) repository\ntests `php-vips` against `imagick` and `gd`. On that test, and on my laptop,\n`php-vips` is around four times faster than `imagick` and needs 10 times\nless memory.\n\nPrograms that use libvips don't manipulate images directly, instead they\ncreate pipelines of image processing operations starting from a source\nimage. When the pipe is connected to a destination, the whole pipeline\nexecutes at once and in parallel, streaming the image from source to\ndestination in a set of small fragments.\n\n### Install\n\nYou need to [install the libvips\nlibrary](https://www.libvips.org/install.html). It's in the linux\npackage managers, homebrew and MacPorts, and there are Windows binaries on\nthe vips website. For example, on Debian:\n\n```\nsudo apt-get install --no-install-recommends libvips42\n```\n\n(`--no-install-recommends` stops Debian installing a *lot* of extra packages)\n\nOr macOS:\n\n```\nbrew install vips\n```\n\nYou'll need to [enable FFI in your\nPHP](https://www.php.net/manual/en/ffi.configuration.php), then add vips\nto your `composer.json`:\n\n```\n\"require\": {\n    \"jcupitt/vips\" : \"2.4.0\"\n}\n```\n\nphp-vips does not yet support preloading, so you need to enable FFI globally.\nThis has some security implications, since anyone who can run php on your\nserver can use it to call any native library they have access to.\n\nOf course if attackers are running their own PHP code on your webserver you\nare probably already toast, unfortunately.\n\nFinally, on php 8.3 and later you need to disable stack overflow\ntests. php-vips executes FFI callbacks off the main thread and this confuses\nthose checks, at least in php 8.3.0.\n\nAdd:\n\n```\nzend.max_allowed_stack_size=-1\n```\n\nTo your `php.ini`.\n\n### Example\n\n```php\n#!/usr/bin/env php\n\u003c?php\nrequire __DIR__ . '/vendor/autoload.php';\nuse Jcupitt\\Vips;\n\n// handy for Windows\nVips\\FFI::addLibraryPath(\"C:/vips-dev-8.16/bin\");\n\n// check libvips version\necho 'libvips version: ' . Vips\\Config::version() . PHP_EOL;\n\n// fast thumbnail generator\n$image = Vips\\Image::thumbnail('somefile.jpg', 128);\n$image-\u003ewriteToFile('tiny.jpg');\n\n// load an image, get fields, process, save\n$image = Vips\\Image::newFromFile($argv[1]);\necho \"width = $image-\u003ewidth\\n\";\n$image = $image-\u003einvert();\n$image-\u003ewriteToFile($argv[2]);\n```\n\nRun with:\n\n```\n$ composer install\n$ ./try1.php ~/pics/k2.jpg x.tif\n```\n\nSee `examples/`. We have a [complete set of formatted API\ndocs](https://libvips.github.io/php-vips/classes/Jcupitt-Vips-Image.html).\n\n\n### How it works\n\nphp-vips uses [php-ffi](https://www.php.net/manual/en/book.ffi.php) to\ncall directly into the libvips binary. It introspects the library binary\nand presents the methods it finds as members of the `Image` class.\n\nThis means that the API you see depends on the version of libvips that\nphp-vips finds at runtime, and not on php-vips. php-vips documentation assumes\nyou are using the latest stable version of the libvips library.\n\nThe previous php-vips version that relied on a binary extension\nand not on php-ffi is still available and supported in [the 1.x\nbranch](https://github.com/libvips/php-vips/tree/1.x).\n\n### Introduction to the API\n\nAlmost all methods return a new image as the result, so you can chain them.\nFor example:\n\n```php\n$new_image = $image-\u003emore(12)-\u003eifthenelse(255, $image);\n```\n\nwill make a mask of pixels greater than 12, then use the mask to set pixels to\neither 255 or the original image.\n\nNote that libvips operators always make new images, they don't modify existing\nimages, so after the line above, `$image` is unchanged.\n\nYou can use long, double, array and image as parameters. For example:\n\n```php\n$image = $image-\u003eadd(2);\n```\n\nto add two to every band element, or:\n\n```php\n$image = $image-\u003eadd([1, 2, 3]);\n```\n\nto add 1 to the first band, 2 to the second and 3 to the third. Or:\n\n```php\n$image = $image-\u003eadd($image2);\n```\n\nto add two images. Or: \n\n```php\n$image = $image-\u003eadd([[1, 2, 3], [4, 5, 6]]);\n```\n\nTo make a 3 x 2 image from the array, then add that image to the original.\n\nAlmost all methods can take an extra final argument: an array of options.\nFor example:\n\n```php\n$image-\u003ewriteToFile(\"fred.jpg\", [\"Q\" =\u003e 90]);\n```\n\n`php-vips` comes [with API\ndocs](https://libvips.github.io/php-vips/classes/Jcupitt-Vips-Image.html).\nTo regenerate these from your sources, type:\n\n```\n$ vendor/bin/phpdoc\n```\n\nAnd look in `docs/`.\n\nUnfortunatly, due to php-doc limitations, these do not list every option\nto every operation. For a full API description you need to see the main\nlibvips documentation:\n\nhttps://libvips.org/API/current\n\n### Test and install\n\n```\n$ composer install\n$ composer test\n$ vendor/bin/phpdoc\n```\n\n### Regenerate auto docs\n\n```\n$ cd src\n$ ../examples/generate_phpdoc.py\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibvips%2Fphp-vips","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibvips%2Fphp-vips","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibvips%2Fphp-vips/lists"}