libvips / php-vips

php binding for libvips
MIT License
606 stars 24 forks source link

Mozjpeg in v2 #153

Closed andrews05 closed 2 years ago

andrews05 commented 2 years ago

I've just upgraded to v2 (after enabling FFI). Everything is working except the mozjpeg save options. Uncaught Jcupitt\Vips\Exception: optional argument 'optimize-coding' does not exist This was working fine with v1. Is there something I need to configure to enable this? Note I haven't changed my libvips install, only the composer package version.

jcupitt commented 2 years ago

Hi @andrews05,

I'd guess you have two libvipses in your system and php-ffi is picking up the wrong one.

Try printing Vips\Config::version() and checking the version number.

You can also add:

Vips\Config::setLogger(new Vips\DebugLogger());

Somewhere near the start of your code, the log output can be useful.

andrews05 commented 2 years ago

Pretty sure I only have one. Here's the debug output, v8.11.4. Should I upgrade?

debug: thumbnail {"instance":null,"arguments":["/testimage.jpg",78,{"height":78,"crop":"centre"}]}
debug: init {"library":"libvips.so.42"}
debug: init {"vips_init":0}
debug: init {"libvips version":[8,11,4]}
debug: init ["binding ..."]
debug: init ["done"]
debug: thumbnail {"introspect":"thumbnail:\n  filename:\n    flags: 19\n      REQUIRED\n      CONSTRUCT\n      INPUT\n    blurb: Filename to read from\n    type: gchararray\n  out:\n    flags: 35\n      REQUIRED\n      CONSTRUCT\n      OUTPUT\n    blurb: Output image\n    type: VipsImage\n  width:\n    flags: 19\n      REQUIRED\n      CONSTRUCT\n      INPUT\n    blurb: Size to this width\n    type: gint\n  height:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: Size to this height\n    type: gint\n  size:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: Only upsize, only downsize, or both\n    type: VipsSize\n  no_rotate:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: Don't use orientation tags to rotate image upright\n    type: gboolean\n  crop:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: Reduce to fill target rectangle, then crop\n    type: VipsInteresting\n  linear:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: Reduce in linear light\n    type: gboolean\n  import_profile:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: Fallback import profile\n    type: gchararray\n  export_profile:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: Fallback export profile\n    type: gchararray\n  intent:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: Rendering intent\n    type: VipsIntent\n  auto_rotate:\n    flags: 82\n      CONSTRUCT\n      INPUT\n      DEPRECATED\n    blurb: Use orientation tags to rotate image upright\n    type: gboolean\nrequired input: filename, width\nrequired output: out\noptional input: height, size, no_rotate, crop, linear, import_profile, export_profile, intent, auto_rotate\noptional output: \nmember_this: \nmethod args: filename, width\n"}
debug: set {"filename":"/testimage.jpg"}
debug: set {"width":78}
debug: set {"height":78}
debug: set {"crop":"centre"}
debug: get {"out":"Jcupitt\\Vips\\Image::__set_state(array(\n   'pointer' => \n  FFI\\CData::__set_state(array(\n  )),\n   'gObject' => \n  FFI\\CData::__set_state(array(\n  )),\n   'pointer' => \n  FFI\\CData::__set_state(array(\n  )),\n   'pointer' => \n  FFI\\CData::__set_state(array(\n  )),\n))"}
debug: thumbnail {"result":"Jcupitt\\Vips\\Image::__set_state(array(\n   'pointer' => \n  FFI\\CData::__set_state(array(\n  )),\n   'gObject' => \n  FFI\\CData::__set_state(array(\n  )),\n   'pointer' => \n  FFI\\CData::__set_state(array(\n  )),\n   'pointer' => \n  FFI\\CData::__set_state(array(\n  )),\n))"}
debug: VipsForeignSaveJpegFile {"instance":"{\"width\":78,\"height\":78,\"bands\":3,\"format\":\"uchar\",\"interpretation\":\"srgb\"}","arguments":["/testimage/78x78.jpg",{"strip":true,"Q":85,"optimize-coding":true,"interlace":true,"trellis-quant":true,"overshoot-deringing":true,"optimize-scans":true,"quant-table":3}]}
debug: VipsForeignSaveJpegFile {"introspect":"VipsForeignSaveJpegFile:\n  in:\n    flags: 19\n      REQUIRED\n      CONSTRUCT\n      INPUT\n    blurb: Image to save\n    type: VipsImage\n  filename:\n    flags: 19\n      REQUIRED\n      CONSTRUCT\n      INPUT\n    blurb: Filename to save to\n    type: gchararray\n  Q:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: Q factor\n    type: gint\n  profile:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: ICC profile to embed\n    type: gchararray\n  optimize_coding:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: Compute optimal Huffman coding tables\n    type: gboolean\n  interlace:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: Generate an interlaced (progressive) jpeg\n    type: gboolean\n  no_subsample:\n    flags: 82\n      CONSTRUCT\n      INPUT\n      DEPRECATED\n    blurb: Disable chroma subsample\n    type: gboolean\n  trellis_quant:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: Apply trellis quantisation to each 8x8 block\n    type: gboolean\n  overshoot_deringing:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: Apply overshooting to samples with extreme values\n    type: gboolean\n  optimize_scans:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: Split spectrum of DCT coefficients into separate scans\n    type: gboolean\n  quant_table:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: Use predefined quantization table with given index\n    type: gint\n  subsample_mode:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: Select chroma subsample operation mode\n    type: VipsForeignSubsample\n  strip:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: Strip all metadata from image\n    type: gboolean\n  background:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: Background value\n    type: VipsArrayDouble\n  page_height:\n    flags: 18\n      CONSTRUCT\n      INPUT\n    blurb: Set page height for multipage save\n    type: gint\nrequired input: in, filename\nrequired output: \noptional input: Q, profile, optimize_coding, interlace, no_subsample, trellis_quant, overshoot_deringing, optimize_scans, quant_table, subsample_mode, strip, background, page_height\noptional output: \nmember_this: in\nmethod args: \n"}
debug: set {"in":"{\"width\":78,\"height\":78,\"bands\":3,\"format\":\"uchar\",\"interpretation\":\"srgb\"}"}
debug: set {"filename":"/testimage/78x78.jpg"}
debug: set {"strip":true}
debug: set {"Q":85}
error: optional argument 'optimize-coding' does not exist []

And here's the vips cli output, same version, showing optimize-coding.

> vips -v jpegsave
vips-8.11.4-Thu Sep 23 09:40:01 UTC 2021
save image to jpeg file
usage:
   jpegsave in filename [--option-name option-value ...]
where:
   in           - Image to save, input VipsImage
   filename     - Filename to save to, input gchararray
optional arguments:
   Q            - Q factor, input gint
                        default: 75
                        min: 1, max: 100
   profile      - ICC profile to embed, input gchararray
   optimize-coding - Compute optimal Huffman coding tables, input gboolean
   ...
andrews05 commented 2 years ago

Figured it out, it seems v2 expects underscores instead of dashes: optimize_coding Is this change expected? [edit] Oh I see, v1 accepted either underscores or dashes. I guess I shouldn't really have been using dashes at all.

jcupitt commented 2 years ago

Ah, well done!

No, you're supposed to be able to use either, this sounds like a silly mistake. I'll have a look.

jcupitt commented 2 years ago

OK, I think it's fixed in master, and I credited you in the changelog (hope that's OK).

Thanks for pointing out this dumbness!

andrews05 commented 2 years ago

Awesome, thanks heaps!