0

I am attempting to use the libvips package on Windows 11.

I have installed the composer package "jcupitt/vips": "2.0.0"

My local PHP setup is laragon, and I have enabled the FFI extension for PHP.

I have installed libvips binary for Windows and added it to the path. It works when I call it from the command line directly. Example: vips invert input.png output.png

When running the following file (which uses FFI):

<?php
require dirname(dirname(__DIR__)) . '/vendor/autoload.php';
use Jcupitt\Vips;

// fast thumbnail generator
$image = Vips\Image::thumbnail('example-rug.jpg', 128);
$image->writeToFile('tiny.jpg');

Fatal error: Uncaught FFI\Exception: Failed resolving C function 'g_malloc' in C:\laragon\www\efc\rugz\vendor\jcupitt\vips\src\Config.php:773 Stack trace: #0 C:\laragon\www\efc\rugz\vendor\jcupitt\vips\src\Config.php(773): FFI::cdef('// we need the ...', 'libvips-42.dll') #1 C:\laragon\www\efc\rugz\vendor\jcupitt\vips\src\Config.php(195): Jcupitt\Vips\Config::init() #2 C:\laragon\www\efc\rugz\vendor\jcupitt\vips\src\Config.php(259): Jcupitt\Vips\Config::ffi() #3 C:\laragon\www\efc\rugz\vendor\jcupitt\vips\src\Image.php(712): Jcupitt\Vips\Config::filenameGetFilename('..\example-rug....') #4 C:\laragon\www\efc\rugz\src\examples\bench.php(8): Jcupitt\Vips\Image::newFromFile('..\example-rug....', Array) #5 {main}

Next FFI\Exception: Failed resolving C function 'g_free' in C:\laragon\www\efc\rugz\vendor\jcupitt\vips\src\Config.php:773 Stack trace: #0 C:\laragon\www\efc\rugz\vendor\jcupitt\vips\src\Config.php(773): FFI::cdef('// we need the ...', 'libvips-42.dll') #1 C:\laragon\www\efc\rugz\vendor\jcupitt\vips\src\Config.php in C:\laragon\www\efc\rugz\vendor\jcupitt\vips\src\Config.php on line 773

All I could think is that these are 2 glib functions and maybe I do not have the glib dll file?

I checked the vips bin folder, and libglib-2.0-0.dll is found there. This is in the same bin folder, so it should be found at the path if necessary.

I know this is being pulled in via the libvips-42.dll, because if I rename libglib-2.0-0.dll file, the FFI output becomes:

Fatal error: Uncaught FFI\Exception: Failed loading 'libvips-42.dll'

The last bit of info I can provide is that the offending portion of the command fed to FFI appears to be:

void* g_malloc (size_t size);
void g_free (void* data);
  • You need to get the libvips bin area on the PATH used by your web server. You might need to dig into the config a bit. Use phpinfo() to verify that your scripts are seeing the correct value. – jcupitt May 21 '22 at 16:38
  • @jcupitt - I can confirm from phpinfo that the vips bin folder is first in the `Path => C:\vips\vips-dev-8.12\bin;` It does find the vips program, but it seemingly fails to understand `g_malloc` and `g_free` commands in FFI. It could definitely still be a config issue, just not sure what other dependencies I may be missing? Or if this is potentially a bug in the latest windows binaries? – Keith Bauer May 23 '22 at 13:26
  • It could perhaps be a php-vips bug, I've opened an issue here: https://github.com/libvips/php-vips/issues/144 let's move discussion to github (stackoverflow is not great for debugging things like this). – jcupitt May 23 '22 at 15:37

2 Answers2

0

Guess libvips-42.dll has to be manually provided:
https://github.com/libvips/build-win64-mxe/releases

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Can you elaborate? I have downloaded the binary `vips-dev-w64-all-8.12.2.zip` and added it to my PATH in windows. I can successfully call vips from cmd. The script using FFI also successfully finds the `libvips-42.dll` file, it just pukes when I hits a glib statement – Keith Bauer May 23 '22 at 13:21
  • @KeithBauer You may need just the same version used at build time. There's no `ldd` on Windows, but likely other tools to inspect DLL (sorry but I've forgot the name). – Martin Zeitler May 23 '22 at 16:19
0

This is fixed in v2.0.3:

https://github.com/libvips/php-vips/pull/146

Just update and it'll work (hopefully).

jcupitt
  • 10,213
  • 2
  • 23
  • 39