'libvips FFI use on Windows PHP cannot find glib functions
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);
Solution 1:[1]
Guess libvips-42.dll has to be manually provided:
https://github.com/libvips/build-win64-mxe/releases
Solution 2:[2]
from os import link, name
from os import system
import os
import requests
import json
from datetime import timedelta
from datetime import datetime
import csv
import time
from bs4 import BeautifulSoup as soup
from requests.models import ReadTimeoutError, Response
import colorama
from colorama import Fore, Back, Style
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from discord_webhook import DiscordWebhook, DiscordEmbed
from bs4 import BeautifulSoup as bs
import threading
import concurrent.futures
session = requests.session()
r = session.get("https://www.mirapodo.de/tommy-hilfiger-gummistiefel-cognac-4545847.html")
def get_sizes_instock():
soup = bs(r, 'lxml')
productscraper = soup.find('div',{'class':"ProdSizeSelect js-prod-variant-select"})
allsizes = productscraper.find("value").text
producttext = productscraper
print(producttext)
Solution 3:[3]
from pprint import pp
import requests
from bs4 import BeautifulSoup
def main(url):
r = requests.get(url)
soup = BeautifulSoup(r.text, 'lxml')
sizes = [x.text for x in soup.select(
'.ProdSizeSelect option:nth-child(n+2)')]
pp(sizes)
main('https://www.mirapodo.de/tommy-hilfiger-gummistiefel-cognac-4545847.html')
Output:
['36 (EU)',
'37 (EU) - Ausverkauft',
'38 (EU)',
'39 (EU) - Ausverkauft',
'40 (EU) - Ausverkauft',
'41 (EU) - Ausverkauft',
'42 (EU)']
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Martin Zeitler |
| Solution 2 | Tassilo Von Loeffelholz |
| Solution 3 | αԋɱҽԃ αмєÑιcαη |
