Code Monkey home page Code Monkey logo

php-vips-ext's Introduction

libvips: an image processing library

CI Fuzzing Status Coverity Status Gitter

Introduction

libvips is a demand-driven, horizontally threaded image processing library. Compared to similar libraries, libvips runs quickly and uses little memory. libvips is licensed under the LGPL 2.1+.

It has around 300 operations covering arithmetic, histograms, convolution, morphological operations, frequency filtering, colour, resampling, statistics and others. It supports a large range of numeric types, from 8-bit int to 128-bit complex. Images can have any number of bands. It supports a good range of image formats, including JPEG, JPEG2000, JPEG-XL, TIFF, PNG, WebP, HEIC, AVIF, FITS, Matlab, OpenEXR, PDF, SVG, HDR, PPM / PGM / PFM, CSV, GIF, Analyze, NIfTI, DeepZoom, and OpenSlide. It can also load images via ImageMagick or GraphicsMagick, letting it work with formats like DICOM.

It comes with bindings for C, C++, and the command-line. Full bindings are available for :

Language Binding
Ruby ruby-vips
Python pyvips
PHP php-vips
C# / .NET NetVips
Go govips
Lua lua-vips
Crystal crystal-vips
Elixir vix

libvips is used as an image processing engine by:

sharp (on node.js)
imgproxy
bimg
sharp for Go
Ruby on Rails
carrierwave-vips
mediawiki
PhotoFlow

and others. The official libvips GUI is nip2, a strange combination of a spreadsheet and a photo editor.

Install

There are packages for most Unix-like operating systems, including macOS. Check your package manager.

There are binaries for Windows in releases.

The libvips website has detailed install notes.

Building from source

libvips uses the Meson build system, version 0.56 or later. Meson can use ninja, Visual Studio or XCode as a backend, so you'll also need one of them.

libvips must have build-essential, pkg-config, libglib2.0-dev, libexpat1-dev. See the Dependencies section below for a full list of the libvips optional dependencies.

There are basic bash completions in completions/, see the README in there.

Cheatsheet

cd libvips-x.y.x
meson setup build --prefix /my/install/prefix
cd build
meson compile
meson test
meson install

Check the output of meson setup carefully and make sure it found everything you wanted it to find. Add arguments to meson setup to change the build configuration.

  • Add flags like -Dnsgif=false to turn libvips options on and off, see meson_options.txt for a list of all the build options libvips supports.

  • Add flags like -Dmagick=disabled to turn libvips dependencies on and off, see meson_options.txt and the list below for a summary of all the libvips dependencies.

  • You might need to add --libdir lib on Debian if you don't want the arch name in the library path.

  • Add --default-library static for a static build.

  • Use eg. CC=clang CXX=clang++ meson setup ... to change compiler.

  • You can have many build-dir, pick whatever names you like, for example one for release and one for debug.

There's a more comprehensive test suite you can run once libvips has been installed. Use pytest in the libvips base directory.

Optional dependencies

If suitable versions are found, libvips will add support for the following libraries automatically. Packages are generally found with pkg-config, so make sure that is working.

libjpeg

Anything that is compatible with the IJG JPEG library. Use mozjpeg if you can. Another option is libjpeg-turbo.

libexif

If available, libvips adds support for EXIF metadata in JPEG files.

librsvg

The usual SVG loader. If this is not present, vips will try to load SVGs via imagemagick instead.

PDFium

If present, libvips will attempt to load PDFs with PDFium. Download the prebuilt pdfium binary from:

https://github.com/bblanchon/pdfium-binaries

Untar to the libvips install prefix, for example:

cd ~/vips
tar xf ~/pdfium-linux.tgz

Create a pdfium.pc like this (update the version number):

VIPSHOME=/home/john/vips
cat > $VIPSHOME/lib/pkgconfig/pdfium.pc << EOF
     prefix=$VIPSHOME
     exec_prefix=\${prefix}
     libdir=\${exec_prefix}/lib
     includedir=\${prefix}/include
     Name: pdfium
     Description: pdfium
     Version: 4290
     Requires:
     Libs: -L\${libdir} -lpdfium
     Cflags: -I\${includedir}
EOF

If PDFium is not detected, libvips will look for poppler-glib instead.

poppler-glib

The Poppler PDF renderer, with a glib API. If this is not present, vips will try to load PDFs via imagemagick.

cgif

If available, libvips will save GIFs with cgif. If this is not present, vips will try to save gifs via imagemagick instead.

libarchive

If available, libvips adds support for creating image pyramids with dzsave.

libtiff

The TIFF library. It needs to be built with support for JPEG and ZIP compression. 3.4b037 and later are known to be OK.

fftw3

If libvips finds this library, it uses it for fourier transforms.

lcms2

If present, vips_icc_import(), vips_icc_export() and vips_icc_transform() can be used to manipulate images with ICC profiles.

libspng

If present, libvips will load and save PNG files using libspng. If not, it will look for the standard libpng package.

libimagequant, quantizr

If one of these quantisation packages is present, libvips can write 8-bit palette-ised PNGs and GIFs.

ImageMagick, or optionally GraphicsMagick

If available, libvips adds support for loading and saving all libMagick-supported image file types. You can enable and disable load and save separately.

Imagemagick 6.9+ needs to have been built with --with-modules. Most packaged IMs are, I think.

If you are going to be using libvips with untrusted images, perhaps in a web server, for example, you should consider the security implications of enabling a package with such a large attack surface.

pangocairo

If available, libvips adds support for text rendering. You need the package pangocairo in pkg-config --list-all.

highway

If present, libvips will accelerate some operations with SIMD. If not, it will look for the orc-0.4 package.

matio

If available, vips can load images from Matlab save files.

cfitsio

If available, vips can load FITS images.

libwebp

If available, vips can load and save WebP images.

libniftiio

If available, vips can load and save NIfTI images.

OpenEXR

If available, libvips will directly read (but not write, sadly) OpenEXR images.

OpenJPEG

If available, libvips will read and write JPEG2000 images.

libjxl

If available, libvips will read and write JPEG-XL images.

OpenSlide

If available, libvips can load OpenSlide-supported virtual slide files: Aperio, Hamamatsu, Leica, MIRAX, Sakura, Trestle, and Ventana.

libheif

If available, libvips can load and save HEIC and AVIF images. Your libheif (in turn) needs to be built with the correct decoders and encoders. You can check with eg.:

$ heif-convert --list-decoders
HEIC decoders:
- libde265 = libde265 HEVC decoder, version 1.0.9
AVIF decoders:
- dav1d = dav1d v6.6.0
- aom = AOMedia Project AV1 Decoder v3.5.0
$ heif-enc --list-encoders
HEIC encoders:
- x265 = x265 HEVC encoder (3.5+1-f0c1022b6) [default]
AVIF encoders:
- aom = AOMedia Project AV1 Encoder v3.5.0 [default]
- svt = SVT-AV1 encoder v1.1.0
- rav1e = Rav1e encoder

Contributors

Code Contributors

This project exists thanks to all the people who contribute.

Organizations

We've had generous financial support from our sponsors. Thank you very much!

php-vips-ext's People

Contributors

chregu avatar jcupitt avatar jmikola avatar kleisauke avatar remicollet avatar tbk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

php-vips-ext's Issues

cannot find vips on pecl

Hi,

i'm trying to install visp package from pecl on my ubuntu server but when i do
pecl install vips

i've that output :

No releases available for package "pecl.php.net/vips"
install failed

How can i install it?

Segfaut in test suite

Probably since recent changes in libvips

Using PHP 7.4, 8.0 with libvips 8.11.3

TEST 12/33 [tests/012.phpt]
========DIFF========
002+ Termsig=11
========DONE========
FAIL new_from_buffer works [tests/012.phpt] 

TEST 33/33 [tests/042.phpt]
========DIFF========
004+ 
005+ Termsig=11
========DONE========
FAIL can set metadata [tests/042.phpt] 
========================================

Opening pdf file

Hello, I am new to php-vips add on.
This functions working good.
$x = vips_image_new_from_file($file)["out"]; (any files tpyes jpg, png, pdf)
vips_image_write_to_file($x, "temp/$filename-to.png",["Q"=>90);

But how can I custom read load $img=vips_pdfload() or $img=vips_pngload() with php plugin.

$img=vips_call("pdfload","file.pdf"); not working; How can i use spefic 300 operations on php ?

8.12.2 Active php ext functions;

ย  | (
ย  | [0] => vips_image_new_from_file
ย  | [1] => vips_image_new_from_buffer
ย  | [2] => vips_image_new_from_array
ย  | [3] => vips_image_write_to_file
ย  | [4] => vips_image_write_to_buffer
ย  | [5] => vips_image_copy_memory
ย  | [6] => vips_image_new_from_memory
ย  | [7] => vips_image_write_to_memory
ย  | [8] => vips_image_write_to_array
ย  | [9] => vips_foreign_find_load
ย  | [10] => vips_foreign_find_load_buffer
ย  | [11] => vips_interpolate_new
ย  | [12] => vips_call
ย  | [13] => vips_image_get
ย  | [14] => vips_image_get_typeof
ย  | [15] => vips_image_set
ย  | [16] => vips_type_from_name
ย  | [17] => vips_image_set_type
ย  | [18] => vips_image_remove
ย  | [19] => vips_error_buffer
ย  | [20] => vips_cache_set_max
ย  | [21] => vips_cache_set_max_mem
ย  | [22] => vips_cache_set_max_files
ย  | [23] => vips_concurrency_set
ย  | [24] => vips_cache_get_max
ย  | [25] => vips_cache_get_max_mem
ย  | [26] => vips_cache_get_max_files
ย  | [27] => vips_cache_get_size
ย  | [28] => vips_concurrency_get
ย  | [29] => vips_version
ย  | )

segmentation fault with php7.4 on mac m1

hey there,
i have found the vips.so extension throwing a segmentation fault on my macbook m1 (arm chip).

./vendor/bin/phpunit
PHPUnit 9.5.5 by Sebastian Bergmann and contributors.

.......................                                           23 / 23 (100%)

Time: 00:00.648, Memory: 60.50 MB

OK (23 tests, 119 assertions)
[1]    64109 segmentation fault  ./vendor/bin/phpunit

disabling the extension removes the segfault at the end of phpunit

php:

PHP 7.4.20 (cli) (built: Jun  3 2021 19:10:14) ( NTS )

vips:


vips property => value
Vips headers version => 8.11.0
Vips library version => 8.11.0
Vips ABI version => 55.0.13
Major version => 8
Minor version => 11
Micro version => 0
Cache max mem => 104857600
Cache max operations => 100
Cache current operations => 0
Cache max open files => 100
Memory allocations => 0
Memory currently allocated => 0
Memory high water => 0
Concurrency => 8
SIMD support with liborc => yes
JPEG support => yes
PNG support => yes
TIFF support => yes
GIF support => yes
OpenEXR support => yes
load OpenSlide => yes
load Matlab => yes
load PDF => yes
load SVG => yes
FITS support => yes
WebP support => yes
HEIF support => yes
load with libMagick => yes
Text rendering support => yes
ICC profile support with lcms => yey
vips -v
vips-8.11.0-Wed Jun  9 18:20:35 UTC 202

thank you for this awesome image library!

Preserving metadata

Hello

I facing a strange issue with VIPS. Here's what i'm doing:

  1. Pickup any image ( between JPG and PNG ).
  2. Copy it to the /tmp/ folder with tempnam().
  3. Add XMP metadata to the temp image using Imagick ( using the profiles functions (setImageProfile/getImageProfile("xmp")) and DomDocument.
  4. Saving the image to the final destination with VIPS.

I use the following when saving the image with VIPS ( see bellow )

  $image =  \Jcupitt\Vips\Image::newFromFile('/tmp/image',['access' => 'sequential']);
  $image->writeToFile($destination.".webp");

I figure that I need to save webp while keeping profile information from the original file ( somehow online exif viewers complain the image doesn't have any ). I have found out that vips has functions to set profile ( "vips_profile_set, function in gate", but the docs show there is no link for it at this time.

Does anyone know a way I can maintain the XMP metadata or write it again into the destination file using only vips? Some servers may not have Imagick with Webp support and I don't want to risk it by opening the file and add XMP again (with Imagemagick), plus I save that extra step.

Thank you in advance.
Best regards

SIGABRT only on php-fpm - php8 on nginx - macOS Catalina and Big Sur

I'm only having this issue on macOS Catalina and Big Sur. Linux works as expected.

โœ… Vips cli works as expected (vips-8.11.0 from homebrew).
โœ… Calling php-vips-ext functions like vips_call() from php cli works as expected.

โŒ Loading a local browser page (homebrew nginx with php-fpm) that calls vips_call() returns 502 Bad Gateway and logs:
WARNING: [pool www] child ... exited on signal 6 (SIGABRT) ...
(running the same php from php cli works as expected)

Also I've found that if vips.so is enabled, any php code that calls openssl (Google cloud apis, stripe api, etc) causes the same 502 Bad Gateway error, even if there are no calls to php-vips-ext functions, but ONLY on php-fpm and ONLY when vips.so is enabled.
If I run the same php code from php CLI, everything works as expected.
If I disable vips.so, all the normal calls to openssl work fine.

I've tried latest php 8.0.7 from homebrew and also php 8.0.6 and 8.0.7 from phpbrew.
I've tried installing php-vips-ext from pecl and also from phpbrew and pickle, also versions 1.0.12 and 1.0.11.
I've tried running php-fpm and nginx as sudo (for permission errors), it didn't work but maybe I messed up something.

Everything worked as expected until last weekend or so, I don't know what changed or what update caused this to start failing.
I've since updated from Catalina to Big Sur thinking it might fix it but... no. ๐Ÿ˜ต

I'd love to fix this or help fix this, but I don't know what my next steps should be.

By the way, thank you very much for vips and php-vips-ext.

Suppress VIPS-WARNING output?

When I try to get certain images (can reproduce it with CMYK images) as tiff, I get a

(banana:11322): VIPS-WARNING **: rounding up IPCT data length

on the console. The warning itself is fine in this case, we don't care much about IPCT data at that point. But the output of the Warning is kinda ugly and distracting. Is there any way to suppress it? The PHP way with the @ in front doesn't work.

configure: error: you need at least libvips 8.2 for this module

Hi, I'm trying to install this ext on MacOs

brew install vips
pecl install vips

But have following error:
configure: error: you need at least libvips 8.2 for this module

vips -v reports: vips-8.8.0-Sat May 11 11:55:18 UTC 2019

MacOs: 10.14.5 (18F132)
PHP 7.3.6
Homebrew 2.1.6

Probably I'm missing something?

windows support

The config.w32 we have at the moment is just a quick copy-paste and hasn't been tested.

We need to find a Windows expert to fix it up and test it.

can't remove metadata on shared image

I tested my project with libvips 8.9 and get lots of
can't remove metadata "orientation" on shared image
warnings. This seems to be expeced according to libvips/libvips#1483 and lovell/sharp#1986

Is this something, which can be improved in the extension or do I have to copy images before applying metadata changes in my application code?

Get EXIF value by field name

<?php

$img = vips_image_new_from_file('/opt/exif.jpg')['out']?? null;

$data = vips_image_get($img, 'exif-Model'); // return -1
$data = vips_image_get($img, 'exif-data'); // return ['out' => "all fields as raw string 50 Kb"]

How to get EXIF value by field name?
Thank.

add support for vips_interpolate_new()

We're testing this extension in our production environment with a small number of requests (A/B-testing). Unfortunately, this error occurs random (around 5% requests passed through php-vips-ext) in our log:

WARNING: [pool www] child 19695 said into stderr: "(banana:19695): GLib-GObject-CRITICAL **: g_value_set_object: assertion 'g_value_type_compatible (G_OBJECT_TYPE (v_object), G_VALUE_TYPE (value))' failed"

We could not figure out where this error comes from and for which image. It looks like the image is successfully returned.

SIGSEGV on OSX

[02-Dec-2017 00:15:55] WARNING: [pool www] child 1618 exited on signal 11 (SIGSEGV) after 55.787030 seconds from start

Is this a know issue ?

I use vips-8.5.9-Fri Dec 1 23:13:50 CET 2017

vips installed with brew and the php extension compile with pecl

OSX 10.13.1

Tested with PHP 7.1 and 7.2 it's pretty random, sometime everything work and it fast ... and sometimes just crash

Thanks

php-vips has not been configured for PDF support

I've encountered an error while using php-vips and I'm encountering this error vips_image_get: field "n-pages".

I've followed all the instructions on the installation of this extension except for the composer. I installed the library using the command found on the composer composer require jcupitt/vips instead of adding "jcupitt/vips" : "1.0.0" on my composer.json. I'm not sure if this is the problem. Thanks!

Issues with installation on php 7.2 on Ubuntu Bionic

Hello @jcupitt

I was trying the code from #39 but I keep getting this error:

Fatal error: Uncaught Error: Call to undefined function Jcupitt\Vips\vips_type_from_name() in 
/var/www/html/backoffice/vendor/jcupitt/vips/src/Utils.php:95 Stack trace: #0 

/var/www/html/imagem.php(169): 

Jcupitt\Vips\Utils::typeFromName('VipsBlob') #1 

I would like to install/upgrade the extension via pecl, but pecl bugs me with that I need vips 8.2 for that.

I have already updated vips, following the gist here. This is not the latest version of vips.

Linux box: Ubuntu Bionic ( 18:04 )

My PHP info has this information:

PHP Version: 7.2
Vips headers version | 8.4.5
Vips library version | 8.4.5
Vips ABI version | -1.-1.-1
Major version | 8
Minor version | 4
Micro version | 5

vips --version issues this:

vips-8.11.0-Tue Apr 13 10:44:43 UTC 2021

composer complains with this ( composer.json entry has ^1.0 has the version required )

Problem 1
    - jcupitt/vips[v1.0.0, ..., v1.0.8] require ext-vips >=0.1.2 -> it is missing from your system. Install or enable PHP's vips extension.
    - Root composer.json requires jcupitt/vips ^1.0 -> satisfiable by jcupitt/vips[v1.0.0, ..., v1.0.8].
This is plenty of evidence that PHP no longer has php-vips-ext installed and enabled.

I am intending in following the last comment from @joppuyo ( see issue #36 ) but I would like to make sure if :

  1. It works with the version I installed from the gist above.
  2. I can install it without libvips-dev ( I fear that installing from the repos may present compat issues, no? )

I have also tried to setup libvips as stated in the docs but to no avail. I could try again, but now following instructions on the github page instead of the website.

On a final note I do wish the distro's repo maintainers add an updated vips to their repos... It's a pain in the neck watching the wonderful things we can do with vips ( and fast ) and not being able to properly update the software...

Best regards and thank you for your patience xD

Release 1.0.5 on PECL

Now that libvips 8.5.2 is released (and to try out the image type sniffers in production), it would be nice to have a release for the PHP vips extension (1.0.5) on PECL.

vips_image_write_to_buffer doesn't support options param?

Really weird as I can't see any big difference between vips_image_write_to_buffer and vips_image_new_from_file. Basically I'm trying this:

<?php

$image = vips_image_new_from_file('/home/nicsev/dev/images/t3pos7b.jpg', ['access' => 'sequential'])['out'];
vips_image_write_to_file($image, 'out.jpg', ['optimize_coding' => true, 'strip' => true, 'Q' => 10]);

$buf = vips_image_write_to_buffer($image, '.jpg', ['optimize_coding' => true, 'strip' => true, 'Q' => 10]);
var_dump($buf);

vips_image_write_to_file works fine. At least with .jpg, it doesn't do anything to .png but at least it doesn't crash.

vips_image_write_to_buffer on the other hand returns -1 on both png and jpg, so long as you give it parameters, though it does work if you don't give it any parameters, or if you give it strings only parameters (but then it seems to ignore them).

Am I an idiot? Also, where can I find the documentation/list over options I can give vips_image_write_to_* functions?

VipsOperation: class "bandand" not found

Hello,
trying to get "bandand" running with php-vips-ext but it's always failing with "VipsOperation: class "bandand" not found".
Any ideas on that?
thx, bye from Austria
Andreas S.

ps) trying to swap all transparent Pixel in an Image with a defined color like mentioned there: libvips/libvips#872 - but struggling with above Error.

Release 1.0.11 test fail on 32-bits

Just used to upgrade to 1.0.11 and test tests/042.phpt started to fail 32-bits on x86 and armv7

vips-1.0.11/tests$ cat 042.diff 
001- pass set_metadata
002+ 
003- pass get_metadata
003+ Notice: Trying to access array offset on value of type int in /mnt/community/php7-pecl-vips/src/vips-1.0.11/tests/042.php on line 21

It means that it fails somehow according to https://github.com/libvips/php-vips-ext/blob/master/vips.c#L1636

PS: here's CI runs

vips ext cause php fpm crash when curl_exec called on mac m1

php 7.4.28
tried with vips 8.12.2 from homebrew
tried with compile vips from source (master branch 8.13.0) and re-compile php-vips-ext to make sure headers and library version matched with 8.13.0
and tried with OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES

still not working. get 502 error from nginx

get this error from php-fpm only: child 90407 exited on signal 11 (SIGSEGV) after 390.827437 seconds from start

related to #42

Async vips_call()

Hi.
Can vips_call work asynchronously?

<?php

vips_call($cmd, $args, function($result){
// callback completion
}) 

Thank.

P.S.
We use PHP cli script daemon mode, libuv as EventLoop.

options for webpsave

Many of the webp options of webpsave are rejected.
I would have assumed that the options for libvips vips_webpsave would be working

The following works:

vips_call('webpsave', $im, ['Q' => 80]);

But the following does not:

vips_call('webpsave', $im, ['smart_subsample' => true]);

It produces the following error (received with vips_error_buffer()):

webpsave: no property named 'smart_subsample'

I get the same result when using vips_image_write_to_file and when using the webpsave method of \Jcupitt\Vips\Image

The following options works with webpsave: Q, lossless, strip
The following options does not work, and produces an error similar to above: preset, near_lossless, smart_subsample, alpha_q

I'm on:
vips version: 8.2.2, vips extension version: 1.0.9, ubuntu 16.04, apache, fpm

Install problem

Error:
PHP Warning: PHP Startup: Unable to load dynamic library 'vips.so' (tried: /usr/local/Cellar/php/7.2.2_14/lib/php/20170718/vips.so (dlopen(/usr/local/Cellar/php/7.2.2_14/lib/php/20170718/vips.so, 9): image not found), /usr/local/Cellar/php/7.2.2_14/lib/php/20170718/vips.so.so (dlopen(/usr/local/Cellar/php/7.2.2_14/lib/php/20170718/vips.so.so, 9): image not found)) in Unknown on line 0

MacOs, php 7.2, install from pecl

Alpinelinux 029 test fails

Trying to upgrade to latest version I faced with failed test alpinelinux/aports#11938

used to add debug information

--- 029.phpt.1	2019-11-26 18:06:12.979624226 +0200
+++ 029.phpt	2019-11-26 18:09:12.768886144 +0200
@@ -13,6 +13,7 @@
   $err = vips_call("add", $image, $rg);
   $msg = vips_error_buffer();
 
+var_dump($msg);
   if ($err == -1 &&
     $msg == "add: not one band or 3 bands\n") {
     echo "pass";

Not I see there's more then one message

$ cat 029.log 

---- EXPECTED OUTPUT
pass
---- ACTUAL OUTPUT
string(106) "vips_realpath: unable to form filename
unix error: No such file or directory
add: not one band or 3 bands
"
---- FAILED

Cant fine where vips_realpath defined to catch error

Error when opening two files with same filename

I have strange error, not sure it it's caused by extension or libvips, and if you will be able to reproduce it.
First - the code i'm using for narrowing the problem:

$originalFile = $path."gun.jpg";
		$resultFile = $uploadPath."result-clean.jpg";

		$image = \Jcupitt\Vips\Image::newFromFile($originalFile);
		$image->writeToFile($resultFile);

		header("Content-Type: image/jpg");
		echo file_get_contents($resultFile);

steps to reproduce:

  1. create file gun.jpg in $path
  2. run once this script
  3. result-clean.jpg will be created
  4. modify gun.jpg ( for example add some line in paint ).
  5. remove result-clean.jpg
  6. re-run this script - result-clean.jpg will be created, however copied from gun.jpg BEFORE modification

when you will change source filename, and re run, modified version will be used.

It looks like there is some kind of cache storing loaded files (?).
I'm using nginx and php-fpm. Restarting fpm "clears" this "cache" ( so new file is used ).

Any ideas ?

new_from_memory / write_to_memory

It would be nice to wrap an image around a memory array or to write an image to a large memory array. This can be useful for moving images between libvips and imagemagick or to calculate the perceptual hash of an image (see below).

The new functions can be named like this:
Extension: new_from_memory, write_to_memory.
php-vips: Image::newFromMemory, ->writeToMemory.

I can open a PR at the php layer to support these new functions if this has been implemented in the extension.

If you are wondering why I need this:
For our test cases we are calculating the perceptual hash of an image (based on the dHash algorithm) to verify the similarity of expected vs actual images (using a distance threshold). It looks like this (so ->copyMemory and ->getpoint are the important ones). If there's a ->writeToMemory function it could be somewhat optimized.

The fastest way to convert from vips to imagick?

Question: Anyone knows what could be the fastest way from a vips resource to an imagick resource (retaining the image, of course) and maybe vice versa. I sometimes need to convert (for example for saving gif) from one to the other.
I basically currently do:

$image = new \Imagick();
$imagick->readImageBlob($vips->pngsave_buffer(['interlace' => false]));

Any better recommended way?

poor resize performance in php as compared to vipsthumbnail tool

Hi John,

vips-8.9.2-Tue Apr 21 09:26:11 UTC 2020
PHP 7.4.6 (cli) (built: May 14 2020 10:03:28) ( NTS )
php-vips-ext 1.0.10
Debian buster
Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz

test image

19M in size

jpg.jpg: 8644x8444 uchar, 3 bands, srgb, jpegload
width: 8644
height: 8444
bands: 3
format: uchar
coding: none
interpretation: srgb
xoffset: 0
yoffset: 0
xres: 11.811
yres: 11.811
filename: jpg.jpg
vips-loader: jpegload
jpeg-multiscan: 0
jpeg-chroma-subsample: 4:2:0
<?php

$image = vips_image_new_from_file('jpg.jpg')['out'];

$args = ['height' => 521, 'size' => 'force', 'no-rotate' => true];

$result = vips_call("thumbnail_image", $image, 8572, $args)['out'];
vips_image_write_to_file($result, __DIR__. '/1.jpg');

time php bechmark.php jpg in php cli mode


php-vips-ext init
enabling vips leak testing ...
vips_image_new_from_file:
vips_image_new_from_file: name = jpg.jpg
vips_php_call_array:
vips_php_call_new: VipsForeignLoadJpegFile
    option_string = "", argc = 1
vips_php_call_array: analyzing input args ...
vips_php_call_array: setting args from option_string ...
vips_php_call_array: setting required input args ...
    VipsForeignLoadJpegFile.filename = "jpg.jpg"
vips_php_call_array: testing argc ...
vips_php_call_array: setting optional input args ...
vips_php_call_array: building ...
vips_php_call_array: getting required output ...
    VipsForeignLoadJpegFile.out = ((VipsImage*) 0x563454aa1020)
vips_php_call_array: getting optional output ...
vips_php_call_free:
vips_php_call_array: success!
vips_call:
vips_php_call_array:
vips_php_call_new: thumbnail_image
    option_string = "", argc = 2
vips_php_call_array: analyzing input args ...
vips_php_call_array: setting args from option_string ...
vips_php_call_array: setting required input args ...
    thumbnail_image.in = ((VipsImage*) 0x563454aa1020)
    thumbnail_image.width = 8572
vips_php_call_array: testing argc ...
vips_php_call_array: setting optional input args ...
vips_php_set_optional_input:
    thumbnail_image.height = 521
    thumbnail_image.size = ((VipsSize) VIPS_SIZE_FORCE)
    thumbnail_image.no-rotate = TRUE
vips_php_call_array: building ...
vips_php_call_array: getting required output ...
    thumbnail_image.out = ((VipsImage*) 0x563454ab7650)
vips_php_call_array: getting optional output ...
vips_php_get_optional_output:
vips_php_call_free:
vips_php_call_array: success!
vips_image_write_to_file:
	0x563454ab7650 -> /var/www/samples-api/tests/1.jpg
vips_php_call_array:
vips_php_call_new: VipsForeignSaveJpegFile
    option_string = "", argc = 1
vips_php_call_array: analyzing input args ...
vips_php_call_array: setting args from option_string ...
vips_php_call_array: setting required input args ...
    VipsForeignSaveJpegFile.in = ((VipsImage*) 0x563454ab7650)
    VipsForeignSaveJpegFile.filename = "php.jpg"
vips_php_call_array: testing argc ...
vips_php_call_array: setting optional input args ...
vips_php_call_array: building ...
vips_php_call_array: getting required output ...
vips_php_call_array: getting optional output ...
vips_php_call_free:
vips_php_call_array: success!
php_free_gobject: 0x563454ab7650
php_free_gobject: 0x563454aa1020
php-vips-ext shutdown
memory: high-water mark 59.73 MB

real	0m17.968s
user	0m14.443s
sys	0m21.947s

time vipsthumbnail --vips-leak --vips-progress jpg.jpg -s 8572x521!

vipsthumbnail temp-23: 8572 x 521 pixels, 8 threads, 128 x 128 tiles, 256 lines in buffer
vipsthumbnail temp-23: done in 0.465s          
memory: high-water mark 94.07 MB

real	0m0.515s
user	0m0.551s
sys	0m0.057s
679K php.jpg
679K tn_jpg.jpg
php.jpg: 8572x521 uchar, 3 bands, srgb, jpegload
php.jpg: width: 8572
php.jpg: height: 521
php.jpg: bands: 3
php.jpg: format: uchar
php.jpg: coding: none
php.jpg: interpretation: srgb
php.jpg: xoffset: 0
php.jpg: yoffset: 0
php.jpg: xres: 11.811
php.jpg: yres: 11.811
php.jpg: filename: php.jpg
php.jpg: vips-loader: jpegload
php.jpg: jpeg-multiscan: 0
php.jpg: jpeg-chroma-subsample: 4:2:0
php.jpg: exif-data: 186 bytes of binary data
php.jpg: resolution-unit: in
php.jpg: exif-ifd0-Orientation: 1 (Top-left, Short, 1 components, 2 bytes)
php.jpg: exif-ifd0-XResolution: 300000/1000 (300.000, Rational, 1 components, 8 bytes)
php.jpg: exif-ifd0-YResolution: 300000/1000 (300.000, Rational, 1 components, 8 bytes)
php.jpg: exif-ifd0-ResolutionUnit: 2 (Inch, Short, 1 components, 2 bytes)
php.jpg: exif-ifd0-YCbCrPositioning: 1 (Centered, Short, 1 components, 2 bytes)
php.jpg: exif-ifd2-ExifVersion: Exif Version 2.1 (Exif Version 2.1, Undefined, 4 components, 4 bytes)
php.jpg: exif-ifd2-ComponentsConfiguration: Y Cb Cr - (Y Cb Cr -, Undefined, 4 components, 4 bytes)
php.jpg: exif-ifd2-FlashPixVersion: FlashPix Version 1.0 (FlashPix Version 1.0, Undefined, 4 components, 4 bytes)
php.jpg: exif-ifd2-ColorSpace: 65535 (Internal error (unknown value 65535), Short, 1 components, 2 bytes)
php.jpg: exif-ifd2-PixelXDimension: 8572 (8572, Long, 1 components, 4 bytes)
php.jpg: exif-ifd2-PixelYDimension: 521 (521, Long, 1 components, 4 bytes)
php.jpg: orientation: 1


tn_jpg.jpg: 8572x521 uchar, 3 bands, srgb, jpegload
tn_jpg.jpg: width: 8572
tn_jpg.jpg: height: 521
tn_jpg.jpg: bands: 3
tn_jpg.jpg: format: uchar
tn_jpg.jpg: coding: none
tn_jpg.jpg: interpretation: srgb
tn_jpg.jpg: xoffset: 0
tn_jpg.jpg: yoffset: 0
tn_jpg.jpg: xres: 11.811
tn_jpg.jpg: yres: 11.811
tn_jpg.jpg: filename: tn_jpg.jpg
tn_jpg.jpg: vips-loader: jpegload
tn_jpg.jpg: jpeg-multiscan: 0
tn_jpg.jpg: jpeg-chroma-subsample: 4:2:0
tn_jpg.jpg: exif-data: 186 bytes of binary data
tn_jpg.jpg: resolution-unit: in
tn_jpg.jpg: exif-ifd0-Orientation: 1 (Top-left, Short, 1 components, 2 bytes)
tn_jpg.jpg: exif-ifd0-XResolution: 300000/1000 (300.000, Rational, 1 components, 8 bytes)
tn_jpg.jpg: exif-ifd0-YResolution: 300000/1000 (300.000, Rational, 1 components, 8 bytes)
tn_jpg.jpg: exif-ifd0-ResolutionUnit: 2 (Inch, Short, 1 components, 2 bytes)
tn_jpg.jpg: exif-ifd0-YCbCrPositioning: 1 (Centered, Short, 1 components, 2 bytes)
tn_jpg.jpg: exif-ifd2-ExifVersion: Exif Version 2.1 (Exif Version 2.1, Undefined, 4 components, 4 bytes)
tn_jpg.jpg: exif-ifd2-ComponentsConfiguration: Y Cb Cr - (Y Cb Cr -, Undefined, 4 components, 4 bytes)
tn_jpg.jpg: exif-ifd2-FlashPixVersion: FlashPix Version 1.0 (FlashPix Version 1.0, Undefined, 4 components, 4 bytes)
tn_jpg.jpg: exif-ifd2-ColorSpace: 65535 (Internal error (unknown value 65535), Short, 1 components, 2 bytes)
tn_jpg.jpg: exif-ifd2-PixelXDimension: 8572 (8572, Long, 1 components, 4 bytes)
tn_jpg.jpg: exif-ifd2-PixelYDimension: 521 (521, Long, 1 components, 4 bytes)
tn_jpg.jpg: orientation: 1

please let me know if you need more info.

Expose Vips library version to PHP

It would be useful to know which vips library version is used, so that the user can be warned, in case it's not the correct one with features missing. I see that there's the vips_version() function in vips, but I couldn't figure out, how to access that from PHP.

Something like

PHP_FUNCTION(vips_version) {
  char digits[256];
  vips_snprintf(digits, 256, "%d.%d.%d", vips_version(0), vips_version(1), vips_version(2));
  RETVAL_STRING(strdup(digits))
}

would maybe do it already (my PHP C know how is too rusty, but I can give it a try, if it's not already accessible through other means)

Does not install on Alpine Linux

Using Alpine (edge/testing) in Docker. After running pecl install vips I get the following output:

...
running: make
/bin/sh /tmp/pear/temp/pear-build-defaultuserBdcDKn/vips-1.0.7/libtool --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1  -I. -I/tmp/pear/temp/vips -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-defaultuserBdcDKn/vips-1.0.7/include -I/tmp/pear/temp/pear-build-defaultuserBdcDKn/vips-1.0.7/main -I/tmp/pear/temp/vips -I/usr/include/php7 -I/usr/include/php7/main -I/usr/include/php7/TSRM -I/usr/include/php7/Zend -I/usr/include/php7/ext -I/usr/include/php7/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/pear/temp/vips/vips.c -o vips.lo
mkdir .libs
 cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/tmp/pear/temp/vips -DPHP_ATOM_INC -I/tmp/pear/temp/pear-build-defaultuserBdcDKn/vips-1.0.7/include -I/tmp/pear/temp/pear-build-defaultuserBdcDKn/vips-1.0.7/main -I/tmp/pear/temp/vips -I/usr/include/php7 -I/usr/include/php7/main -I/usr/include/php7/TSRM -I/usr/include/php7/Zend -I/usr/include/php7/ext -I/usr/include/php7/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/pear/temp/vips/vips.c  -fPIC -DPIC -o .libs/vips.o
In file included from /tmp/pear/temp/vips/vips.c:19:0:
/usr/include/vips/vips.h:85:18: fatal error: glib.h: No such file or directory
 #include <glib.h>
                  ^
compilation terminated.
make: *** [Makefile:194: vips.lo] Error 1
ERROR: `make' failed

Vips version used: 8.5.6
I'm using the following Dockerfile:

FROM    alpine:edge
RUN     apk add --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing \
        vips-tools vips-dev glib-dev php7-dev php7-pear build-base libxml2-dev
RUN     pecl install vips

Although installing from source (version 8.4.5) as described here works fine.

Phpinfo says no lcms

I've built libvips with lcms2 and vipsthumbnail works fine on the command line but my phpinfo says "ICC profile support with lcms: no" and I get an error about icc_import not found when trying to thumbnail a cmyk image. Any idea why the vips extension isn't detecting lcms? Do I need to pass any parameters to pecl when installing?

Trying to understand memory usage with php-fpm

We're using the php-vips-ext together with php-fpm for image manipulation of pictures, mainly for web usage (meaning, they're not huge). All works fine and fast now, but I'm trying to understand the memory usage.

If have currently set vips_cache_set_max_mem to 50MB and vips_cache_set_max_files to 100 (just as a first start). What I see now is that some php-fpm process are using way more than that after some time (the current max is 340MB), it was way less than that before.

I also see a value of 250MB in vips_tracked_get_mem_highwater (not sure that's the one corresponding to the 340MB using memory, but good enough for getting the idea), while vips_tracked_get_mem is around the 50MB.

Is something not releasing that highwater memory? Maybe PHP itself for performance reasons? I can circumvent it with just killing php-fpm after a few hundred requests, that's totally fine, I just try to understand what's happening.

btw, I use https://github.com/pixelb/ps_mem for getting the memory usage of a process, which seems pretty accurate.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.