safe-svg icon indicating copy to clipboard operation
safe-svg copied to clipboard

Optimise already uploaded SVG images

Open vikrampm1 opened this issue 2 years ago • 6 comments

Is your enhancement related to a problem? Please describe.

Optimize existing SVGs when someone triggers a batch regenerate of images, with WP-CLI or a third-party plugin. That way we wouldn't have to build a settings page for that, or a specific mechanism from scratch and the implementation should be quicker. The challenge with the optimizer is that being a JS tool, it cannot utilize the standard PHP hooks so it would take some testing/investigation to see how this could best work.

For more context refer: https://github.com/10up/safe-svg/pull/79

Designs

No response

Describe alternatives you've considered

No response

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

vikrampm1 avatar Oct 20 '22 14:10 vikrampm1

I have done a bit of initial investigation here, but I have been unable to find a viable path for leveraging the same SVGO library added in #79 through a WP php hook that is triggered on batch image regeneration.

The only way I could see this working would be a cli command that installs and runs npm packages to the local filesystem. However, this is not a feasible option for most web hosts.

I think the only viable options here would be: a) Use a different library for batch compression b) Create a browser interface specific to the plugin that would be able to leverage the same library

csloisel avatar Dec 16 '22 20:12 csloisel

@darylldoyle any thoughts on how to handle this based on the research findings above?

jeffpaul avatar Dec 22 '22 23:12 jeffpaul

@jeffpaul unfortunately not. This was initially part of the "pro" package for this reason. It was hard/hacky to do on the server, so I offloaded it to a specific SVGO server I was running to do the compression and then push it back.

Something similar could be done here with the option for people to use their own server? I'm not sure how that sits with the OSP though.

darylldoyle avatar Jan 04 '23 12:01 darylldoyle

@csloisel @darylldoyle are there any known, reliable SVGO servers that we could consider integrating with and allow plugin users to select their preference (and potentially include whatever auth credentials are needed for those services via plugin settings)?

jeffpaul avatar Jan 04 '23 19:01 jeffpaul

@jeffpaul not that I'm aware of. This is what I was hoping for when I originally made the pro plugin. There's a lack of SVGO services (SVGOAAS?).

I've found the following services that say they support SVG optimisation via API, that could be worth looking into:

  • https://kraken.io/
  • https://imageoptim.com/api

The only other option I could see is for 10up to host one, though that'd likely need a larger conversation around what that entails.

darylldoyle avatar Jan 04 '23 20:01 darylldoyle

https://github.com/vector-express/vectorexpress-api#convertor-svgo looks like it might be an option perhaps?

jeffpaul avatar May 08 '23 21:05 jeffpaul