function responsive_image_get_mime_type

responsive_image_get_mime_type($image_style_name, $extension)

Determines the MIME type of an image.

Parameters

string $image_style_name: The image style that will be applied to the image.

string $extension: The original extension of the image (without the leading dot).

Return value

string The MIME type of the image after the image style is applied.

File

core/modules/responsive_image/responsive_image.module, line 474
Responsive image display formatter for image fields.

Code

function responsive_image_get_mime_type($image_style_name, $extension) {
  if ($image_style_name == RESPONSIVE_IMAGE_EMPTY_IMAGE) {
    return 'image/gif';
  }
  // The MIME type guesser needs a full path, not just an extension, but the
  // file doesn't have to exist.
  if ($image_style_name === RESPONSIVE_IMAGE_ORIGINAL_IMAGE) {
    $fake_path = 'responsive_image.' . $extension;
  }
  else {
    $fake_path = 'responsive_image.' . ImageStyle::load($image_style_name)->getDerivativeExtension($extension);
  }
  return Drupal::service('file.mime_type.guesser.extension')->guess($fake_path);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!modules!responsive_image!responsive_image.module/function/responsive_image_get_mime_type/8.1.x