Sharing the Code

Programming stuff that might be useful to others

Tag: Drupal

Retina image fields in Drupal 8

There is a responsive image module built into Drupal 8 that will serve different images by using media queries and multipliers. So you select one image style for 1x devices and another image style for 2x devices. The problem with this is that image styles only output to exact dimensions. So you can’t have an image style that will output half the image size regardless of the input image. My images are all different sizes so I can’t use image styles. Below I outline a method that takes a 2x image, sets the width and height to half of the image size and serves that to all devices.

Read more