wordpress-plugin icon indicating copy to clipboard operation
wordpress-plugin copied to clipboard

[Feature request] Add Tiny_Plugin::compress() for general usage by devs

Open mklepaczewski opened this issue 3 years ago • 2 comments

The plugin covers basic functionality. However, as a developer, I sometimes need to do custom tasks that aren't covered by the plugin (for example, I wrote WP CLI wrapper around the plugin). Compression is currently triggered during various events, but it seems there's no easy way to execute it manually from standalone PHP code. I propose to add Tiny_Plugin::compress(). Ideally, for consistency reasons, all other compression methods should rely on and call it:

  • Tiny_Plugin::compress_on_upload(),
  • Tiny_Plugin::compress_image_from_library(),
  • Tiny_Plugin::compress_image_for_bulk()

I can submit PR if this feature request is accepted.

mklepaczewski avatar Feb 12 '21 09:02 mklepaczewski

Note that I'm aware of Tiny_Image::compress(), but it requires Tiny_Settings which isn't easily available from Tiny_Plugin. For now Tiny_Plugin::settings is just vanilla new Tiny_settings(), but who knows if it stays that in the future ;-)

mklepaczewski avatar Feb 12 '21 09:02 mklepaczewski

Hi Matt,

Thanks for writing us here as well!

I don't think the Tiny_Settings constructor will change any time soon. It's been this way for years already, and I don't see any future need to pass along something dynamic to that constructor. You should therefore be fine instantiating a Tiny_Image with a new Tiny_Settings() and then call the compress function to have all its configured image sizes compressed.

On the other hand, I do see the added value of having an easy to use function to compress an image from code outside of the plugin. For example, a function that only needs the ID of the image you want to compress. That also helps in case we do decide to change the internals of Tiny_Image, Tiny_Settings and the compress method. Feel free to submit a PR for that. Thanks!

mattijsvandruenen avatar Feb 12 '21 14:02 mattijsvandruenen