rosell-dk / webp-convert

Convert jpeg/png to webp with PHP (if at all possible)
MIT License
576 stars 101 forks source link

Extract code for abstract converter into new library #334

Open rosell-dk opened 2 years ago

rosell-dk commented 2 years ago

The new library will basically take care of all related to converting besides the actual converting. But it must be be generic enough to be used with both webp-convert and avif-convert (and other possible libraries, such as one for jpeg 2000).

The AbstractConverter class and its traits can (more or less) be extracted into a this new library (ie "AbstractImageConverter") The loggers can also be put into this library (or a new). Any helpers regarding conversion (that are not worthy of their own library) can go here too. Looking into actual converters, ie "ImageMagick.php", I see there would be a lot of code duplication in AVIFConvert. It should be considered how to avoid that. One idea could be to provide a generic base class for each converter or perhaps a trait instead.

It should be kept in mind that we might want to create a library "ImageConvert" which is able to pull it all together, allowing conversion between "any" image type.

It must not necessarily be implemented exactly as now. I have used a lot of inheritance and traits, but maybe some would be clearer with composition.

rosell-dk commented 2 years ago

Another way around would be to have all the code in a new library "image-convert". webp-convert could simply use that new all-encompassing library

nickchomey commented 7 months ago

I would like to implement something like this as a wordpress plugin - be able to convert to web, avif and any other format, as well as do resizing etc... Wordpress, of course, already has this functionality through imagick, but I'd like to do it with vips. But might as well use something like this package that has compatibility with many converters for maximum compatibility.

Was any more thought or work put into this?

It seems to me that something like ImageConvert would be the best way to do it all - there would surely be 99.9% redundant code between a webp and avif implementation. Better to just make one package that converts between whatever you want by toggling the output format.