10up / safe-svg

Enable SVG uploads and sanitize them to stop XML/SVG vulnerabilities in your WordPress website.
https://wordpress.org/plugins/safe-svg/
GNU General Public License v2.0
270 stars 31 forks source link

Optimise already uploaded SVG images #81

Open vikrampm1 opened 1 year ago

vikrampm1 commented 1 year ago

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

csloisel commented 1 year ago

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

jeffpaul commented 1 year ago

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

darylldoyle commented 1 year ago

@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.

jeffpaul commented 1 year ago

@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)?

darylldoyle commented 1 year ago

@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:

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.

jeffpaul commented 1 year ago

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