diff --git a/core/modules/responsive_image/responsive_image.module b/core/modules/responsive_image/responsive_image.module index 2fa9761..03989dc 100644 --- a/core/modules/responsive_image/responsive_image.module +++ b/core/modules/responsive_image/responsive_image.module @@ -191,7 +191,7 @@ function theme_responsive_image($variables) { $sources = array(); $image = \Drupal::service('image.factory')->get($variables['uri']); - $mime_type = $image->getMimeType(); + $extension = pathinfo($image->getSource(), PATHINFO_EXTENSION); $responsive_image_mapping = ResponsiveImageMapping::load($variables['mapping_id']); // All breakpoints and multipliers. $breakpoints = \Drupal::service('breakpoint.manager')->getBreakpointsByGroup($responsive_image_mapping->getBreakpointGroup()); @@ -210,7 +210,7 @@ function theme_responsive_image($variables) { // Get the dimensions. $dimensions = responsive_image_get_image_dimensions($image_style_name, array('width' => $variables['width'], 'height' => $variables['height'])); // Get MIME type. - $derivative_mime_type = responsive_image_get_mime_type($image_style_name, $mime_type); + $derivative_mime_type = responsive_image_get_mime_type($image_style_name, $extension); $derivative_mime_types[] = $derivative_mime_type; // Add the image source with its width descriptor. When a width @@ -228,7 +228,7 @@ function theme_responsive_image($variables) { break; case 'image_style': // Get MIME type. - $derivative_mime_type = responsive_image_get_mime_type($mapping_definition['image_style'], $mime_type); + $derivative_mime_type = responsive_image_get_mime_type($mapping_definition['image_style'], $extension); $derivative_mime_types[] = $derivative_mime_type; // Add the image source with its multiplier. $srcset[floatval(drupal_substr($multiplier, 0, -1))] = array( @@ -320,9 +320,9 @@ function theme_responsive_image_source($variables) { /** * Determines the dimensions of an image. * - * @param $image_style_name + * @param string $image_style_name * The name of the style to be used to alter the original image. - * @param $dimensions + * @param array $dimensions * An associative array containing: * - width: The width of the source image (if known). * - height: The height of the source image (if known). @@ -347,22 +347,24 @@ function responsive_image_get_image_dimensions($image_style_name, $dimensions) { } /** -* Determines the MIME type of an image. + * Determines the MIME type of an image. * - * @param $image_style_name + * @param string $image_style_name * The image style that will be applied to the image. - * @param $mime_type - * The original MIME type of the image. + * @param string $extension + * The original extension of the image (without the leading dot). * * @return string * The MIME type of the image after the image style is applied. */ -function responsive_image_get_mime_type($image_style_name, $mime_type) { +function responsive_image_get_mime_type($image_style_name, $extension) { if ($image_style_name == RESPONSIVE_IMAGE_EMPTY_IMAGE) { return 'image/gif'; } - ImageStyle::load($image_style_name)->getDerivativeMimeType($mime_type); - return $mime_type; + // The mime type guesser needs a full path, not just an extension, but the + // file doesn't have to exist. + $fake_path = 'responsive_image.' . ImageStyle::load($image_style_name)->getDerivativeExtension($extension); + return Drupal::service('file.mime_type.guesser.extension')->guess($fake_path); } /** @@ -376,4 +378,3 @@ function _responsive_image_image_style_url($style_name, $path) { } return ImageStyle::load($style_name)->buildUrl($path); } -