Images plugin was made because I needed to fetch image-uploads in an exact size, determined by the client.
Due to a limitation in strapis installation script, you will have to install this plugin manually.
In the root of your project, run the following:
npm install strapi-plugin-images --no-save
This will install the plugin node node_modules
folder
mv node_modules/strapi-plugin-images plugins/images
In order for strapi to use this plugin, it has to be moved to the folder plugins
cp node_modules/strapi-generate-plugin/templates/gitignore plugins/images/.gitignore
To keep a clean project, you'll need the .gitignore
plugin template from strapi
When plugin has been installed, you need to allow access to the GET: images
endpoint.
- Navigate to Users & Permissions.
- Pick the role you would like to give permission.
- Scroll down to the section Images.
- Check the
get
endpoint, and press save.
When the plugin is installed, it will add a resize_url
field to each attachment in the response. When the attachment is of a supported mime-type, the field will contain a url for the resizing endpoint.
This endpoint can be called with some transformation parameters.
Examples:
HOST_NAME/images/${image_id}?size=120x120
This example will resize the image to 120px by 120px. It will by default use the "cover" mode.
HOST_NAME/images/${image_id}?size=120x120&mode=contain
This example will resize the image to 120px by 120px. This is explicitly configured to use the contain mode.
This plugin is basically a strapi implementation of Jimp
Checkout the docs.