Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nplowman/jsonapi-reusable-images
Drupal 8 module that provides an additional URL for Image entities that supports on-the-fly scaling and cropping.
https://github.com/nplowman/jsonapi-reusable-images
Last synced: 2 months ago
JSON representation
Drupal 8 module that provides an additional URL for Image entities that supports on-the-fly scaling and cropping.
- Host: GitHub
- URL: https://github.com/nplowman/jsonapi-reusable-images
- Owner: nplowman
- Created: 2019-08-30T22:42:12.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-13T22:43:41.000Z (over 5 years ago)
- Last Synced: 2024-08-03T02:08:36.198Z (6 months ago)
- Language: PHP
- Size: 3.91 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
- drupal-js - nplowman/jsonapi-reusable-images
README
# Installation
This module does not require any configuration. Simply enable this module
and the JSON:API module.# Usage
1. After enabling the module, you should see an additional property in the JSON
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"
}
```2. You can use 'w' and 'h' query parameters with this URL to scale and crop the
image to the size you need.## Examples:
Scale and crop to 200x200 thumbnail:
```http://headless-drupal.docksal/resizable-images/3/nyan.gif?w=200&h=200```
Scale width to 200 pixels and scale height proportionally:
```http://headless-drupal.docksal/resizable-images/3/nyan.gif?w=200```Scale height to 500 pixels and scale width proporitionally:
```http://headless-drupal.docksal/resizable-images/3/nyan.gif?h=500```# Notes
- Supported Image Formats: jpg, png, gif
- Note that animated gifs can be cropped, but only the first frame will be
available in derivative image.
- While the module was built with the use case of JSON:API in mind, it is not a
hard requirement. The resizable_image_url is attached to file entities as a computed
property, and can be also used with the core REST API and custom solutions.# Similar Modules
[Consumer Image Styles](https://www.drupal.org/project/consumer_image_styles)
Consumer Image Styles takes a different approach to solving the same problem as this module.
The advantage of JSON Resizable Images is that it allows you to request a resized
image with any width and height on-the-fly, while Consumer Image Styles requires
you configure preset Image Styles on the Drupal side.