Skip to content

Mozjpeg in v2 #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
andrews05 opened this issue Aug 10, 2022 · 6 comments
Closed

Mozjpeg in v2 #153

andrews05 opened this issue Aug 10, 2022 · 6 comments

Comments

@andrews05
Copy link

andrews05 commented Aug 10, 2022

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
Copy link
Member

jcupitt commented Aug 10, 2022

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
Copy link
Author

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
Copy link
Author

andrews05 commented Aug 11, 2022

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
Copy link
Member

jcupitt commented Aug 11, 2022

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
Copy link
Member

jcupitt commented Aug 11, 2022

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!

jcupitt added a commit that referenced this issue Aug 11, 2022
php-vips 1.x used to allow "-" as a component separator in arg names,
but we forgot to implement this in v2.

Thanks andrews05

See #153
@andrews05
Copy link
Author

Awesome, thanks heaps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants