Experimental project
This is a sandbox project, which contains experimental code for developer use only.
This module was designed for use with Headless Drupal sites and provides a simple way to request custom-sized images on-the-fly from your client applications without having to preconfigure Image Styles beforehand.
Usage
First, enable this module and the JSON:API module.
After enabling the module, you should see an additional property in the JSON:API
response for File Entities named 'resizable_image_url':
attributes: {
drupal_internal__fid: 3,
langcode: "en",
filename: "nyan.gif",
uri: {
value: "public://2019-08/nyan.gif",
url: "/sites/default/files/2019-08/nyan.gif"
},
filemime: "image/gif",
filesize: 761850,
status: true,
created: "2019-08-30T22:53:41+00:00",
changed: "2019-08-30T22:53:48+00:00",
resizable_image_url: "http://example.com/resizable-images/3/nyan.gif"
}
Use this new URL when requesting the image from your client application, and use the 'w' and 'h' query string parameters to specify the width and height you would like. If the query parameters are omitted, the original image will be served.
Usage Examples
Scale and crop to a 200x200 thumbnail:
http://www.mysite.com/resizable-images/3/nyan.gif?w=200&h=200
Scale width to 200 pixels and scale height proportionally:
http://www.mysite.com/resizable-images/3/nyan.gif?w=200
Scale height to 500 pixels and scale width proportionally:
http://www.mysite.com//resizable-images/3/nyan.gif?h=500
Additional Notes
- This module is an early proof-of-concept, and is not recommended for production use.
- Currently supported image formats include jpg, png, and gif.
- Note that animated gifs can be cropped, but only the first frame will be available in derivative image.
Similar Modules
Consumer Image Styles: This module takes a different approach at solving the same problem. The main distinction is that Consumer Image Styles requires you to define available image sizes in Drupal through Image Styles first before they are available to client applications, while JSON:API Resizable Images allows client applications to request custom image sizes directly without prior configuration.