class BitmapFormat (View source)

Helper class for bitmap image formats.

Constants

FORMAT_PNG

Bitmap image format: PNG.

FORMAT_JPEG

Bitmap image format: JPEG.

FORMAT_WEBP

Bitmap image format: WEBP.

FORMAT_GIF

Bitmap image format: GIF.

FORMAT_WBMP

Bitmap image format: WBMP.

FORMAT_XBM

Bitmap image format: XBM.

DEFAULT_JPEG_QUALITY

Default JPEG quality (from 0 to 100) - to be used when there's no (valid) configured value.

DEFAULT_WEBP_QUALITY

Default WEBP quality (from 0 to 100) - to be used when there's no (valid) configured value.

DEFAULT_PNG_COMPRESSIONLEVEL

Default PNG compression level (from 0 to 9) - to be used when there's no (valid) configured value.

Properties

protected Repository $config
protected Numbers $valn
protected string[]|null $allImageFormats

All the image formats (if initialized).

Methods

__construct(Repository $config, Numbers $valn)

Initialize the instance.

string[]
getAllImageFormats()

Get all the image formats.

bool
isFormatValid(string|mixed $format)

Check if a format identifier is valid.

string
getFormatMimeType(string $format)

Get the MIME type for a specific format.

string|mixed
getFormatFromMimeType(string $mimeType, mixed $fallback = '')

Get the bitmap format corresponding to a specific MIME type.

array
getFormatImagineSaveOptions(string $format)

Get the Imagine save options for the specified image format.

string
getFormatFileExtension(string $format)

Get the file extension for the specified format.

$this
setDefaultJpegQuality(int $value)

Set the default JPEG quality.

int
getDefaultJpegQuality()

Get the default JPEG quality.

$this
setDefaultWebpQuality(int $value)

Set the default WEBP quality.

int
getDefaultWebpQuality()

Get the default WEBP quality.

$this
setDefaultPngCompressionLevel(int $value)

Set the default PNG compression level.

int
getDefaultPngCompressionLevel()

Get the default PNG compression level.

string
normalizeFormat(string|mixed $format)

Normalize a format.

Details

__construct(Repository $config, Numbers $valn)

Initialize the instance.

Parameters

Repository $config
Numbers $valn

string[] getAllImageFormats()

Get all the image formats.

Return Value

string[]

bool isFormatValid(string|mixed $format)

Check if a format identifier is valid.

Parameters

string|mixed $format

Return Value

bool

string getFormatMimeType(string $format)

Get the MIME type for a specific format.

Parameters

string $format

One of the BitmapFormat::FORMAT_... constants.

Return Value

string

return an empty string is $format is invalid

string|mixed getFormatFromMimeType(string $mimeType, mixed $fallback = '')

Get the bitmap format corresponding to a specific MIME type.

Parameters

string $mimeType

the MIME type to analyze

mixed $fallback

what to return if $mimeType is not recognized

Return Value

string|mixed

array getFormatImagineSaveOptions(string $format)

Get the Imagine save options for the specified image format.

Parameters

string $format

One of the BitmapFormat::FORMAT_... constants.

Return Value

array

string getFormatFileExtension(string $format)

Get the file extension for the specified format.

Parameters

string $format

One of the BitmapFormat::FORMAT_... constants.

Return Value

string

returns an empty string if $format is invalid

Examples

$bitmapFormat->getFormatFileExtension(BitmapFormat::FORMAT_GIF) === 'gif'

$this setDefaultJpegQuality(int $value)

Set the default JPEG quality.

Parameters

int $value

an integer from 0 to 100

Return Value

$this

int getDefaultJpegQuality()

Get the default JPEG quality.

Return Value

int

an integer from 0 to 100

$this setDefaultWebpQuality(int $value)

Set the default WEBP quality.

Parameters

int $value

an integer from 0 to 100

Return Value

$this

int getDefaultWebpQuality()

Get the default WEBP quality.

Return Value

int

an integer from 0 to 100

$this setDefaultPngCompressionLevel(int $value)

Set the default PNG compression level.

Parameters

int $value

an integer from 0 to 9

Return Value

$this

int getDefaultPngCompressionLevel()

Get the default PNG compression level.

Return Value

int

an integer from 0 to 9

protected string normalizeFormat(string|mixed $format)

Normalize a format.

Parameters

string|mixed $format

Return Value

string