libvips / php-vips-ext

Low-level libvips binding for PHP
MIT License
101 stars 11 forks source link

vips_image_write_to_file seems to don't support options param correctly #3

Closed marhub closed 7 years ago

marhub commented 7 years ago

I'm trying to set quality of jpg file. Code is simple:

$image = \Jcupitt\Vips\Image::newFromFile($data['image']['tmp_name']);
$image->writeToFile($filePath,["Q"=>10]);

this is not working.

However if i set it in $filePath, it is working correctly:

$filepath.="[Q=10]"
jcupitt commented 7 years ago

Oh dear, you're right, vips_image_write_to_file() was not handling options at all.

I've added this, added a test, and upload 1.0.2 with the fix to pecl.

With this program:

#!/usr/bin/env php
<?php

require __DIR__ . '/vendor/autoload.php';

use Jcupitt\Vips;

$im = Vips\Image::newFromFile($argv[1]);
$im->writeToFile($argv[2], ["Q" => 20]);
$im->writeToFile($argv[3], ["Q" => 90]);

I now see:

john@kiwi:~/try$ ./try241.php ~/pics/k2.jpg x.jpg y.jpg
john@kiwi:~/try$ ls -l x.jpg y.jpg 
-rw-r--r-- 1 john john  92440 Dec  6 10:15 x.jpg
-rw-r--r-- 1 john john 386676 Dec  6 10:15 y.jpg

Thank you very much for reporting this dumbness!

marhub commented 7 years ago

I confirm that now it's working.