module

MJ::Arcana::Convert

Re-encode an image to the format the caller asked for.

Needed because the providers do not agree on what they return, and the whole promise of pools is that moving load between them changes nothing but the queue:

Runware honours outputFormat — asks for webp, gets lossy VP8 webp OpenAI direct honours output_format, and output_compression for the lossy/lossless choice (left alone it returns LOSSLESS webp, 8x the bytes) Google direct ignores the question entirely and returns JPEG, always

Without this, asking the google pool for webp got JPEG bytes labelled webp — a caller storing by extension would write a .webp file containing a JPEG. Converting keeps the pools genuinely interchangeable; labelling alone would not.

Constants

QUALITY = 80

Quality for lossy targets. 80 lands near the other pools (measured: Runware webp 0.11 bytes/pixel, OpenAI direct at compression 80 gives 0.04) so panel sizes stay comparable whichever pool served the request.

Class methods

available?
Source
convert(bytes : Bytes, target : String) : Bytes
Source
ensure(bytes : Bytes, target : String) : Bytes

Returns the bytes unchanged when they are already in the target format — the common case, so the usual path costs one sniff and no subprocess.

Source

Nested types