php-imagine / Imagine

PHP Object Oriented image manipulation library
https://imagine.readthedocs.io
Other
4.42k stars 530 forks source link

Split getSupportedFormats into getSupportedInputFormats and getSupportedOutputFormats #815

Open alexander-schranz opened 2 years ago

alexander-schranz commented 2 years ago

Description

I did see a new getSupportedFormats was added. Which I think is a great addition. I'm not sure if we should go with a general supportedFormats. As from my point of view there are 2 supportedFormats methods needed. One for inputFormats so which format I can in general read with that adapter and on for outputFormats which formats I can output. Example depending on the installed imagemagick libraries I can also read adobe files but can not output them, same for other vector files like svg can be read but not outputted

Example Interface changes:

/** @return string[] */
public function getSupportedInputFormats(): array;

/** @return string[] */
public function getSupportedOutputFormats(string $inputFormat = null): array;

Why?

Why we should implement something like this. As example I have the imagine imagick and imagine vips adapter installed. For all things I want to use the vips adapter aslong as the vips adapter support the specific inputFormat -> outputFormat if not I will fallback to the imagick adapter which supports more formats.

Another usecase is I want to use SVGImagine adapter to convert resize svg -> svg but when I need to convert svg->png I want to use the Imagick adapter.

mlocati commented 2 years ago

Yep, that'd be nice, but I don't think it's possible. For example, we know the formats supported by Imagick by using the Imagick::queryFormats() method, which doesn't give details about encoding/decoding capabilities...

ausi commented 2 years ago

which doesn't give details about encoding/decoding capabilities

But we could report them then for both, intput and output formats. And in the future we could add better checks if possible.