function GDToolkit::checkAvifSupport

Checks if AVIF can encode image.

This method tries to create an AVIF image and save it to disk via imageavif(). If that fails, it's likely a codec missing, or the function was disabled. This is an expensive operation to run, so we cache its result.

Return value

bool TRUE if AVIF is fully supported, FALSE otherwise.

1 call to GDToolkit::checkAvifSupport()
GDToolkit::supportedTypes in core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php
Returns a list of image types supported by the toolkit.

File

core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php, line 557

Class

GDToolkit
Defines the GD2 toolkit for image manipulation within Drupal.

Namespace

Drupal\system\Plugin\ImageToolkit

Code

protected static function checkAvifSupport() : bool {
  static $supported = NULL;
  if ($supported !== NULL) {
    return $supported;
  }
  $tempFile = fopen('php://memory', 'r+');
  $supported = function_exists('imageavif') && imageavif(imagecreatetruecolor(1, 1), $tempFile, 0, 10) && fstat($tempFile)['size'] > 0;
  fclose($tempFile);
  return $supported;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.