Overview:
The Nuxt Image Loader module is a powerful tool that allows users to automatically resize, rotate, blur, watermark, and crop images based on defined rules. By intercepting image requests on the server side, the module can respond with the original image or a processed image if a query string is appended to the image URL. This module works for all Nuxt deployment modes and uses the GraphicsMagick for node package for image processing capabilities.
Features:
- Automatic image processing: The Nuxt Image Loader module automatically resizes, rotates, blurs, adds watermarks, and crops images based on defined rules.
- Server-side image interception: The module intercepts incoming image requests on the server side and responds with either the source image or a processed image.
- Custom image styles: Users can define custom image styles in the nuxt.config.json file, specifying different image processing settings for each style.
- Responsive image support: Users can define responsive image styles that can be used with the
<nuxt-img>component, making it easy to display different versions of an image based on device size. - Supports all Nuxt deployment modes: The module works seamlessly with all Nuxt deployment modes, including server rendered, statically generated, and hot module replacement.
Installation:
To install the Nuxt Image Loader module, follow these steps:
- Ensure that the
graphicsmagickpackage is installed on the same host system or container where your application lives. - Add the module as a dependency in your project by running
npm install nuxt-image-loader.
Next, in your nuxt.config.js file, include the following configuration:
{
modules: [
'nuxt-image-loader'
],
... // Other configurations
}
In the same nuxt.config.js file, you can define the image processing settings by adding the imageStyles option. For example:
{
imageStyles: {
thumbnail: {
actions: ['resize|100|100', 'crop|50|50'],
macros: ['scaleAndCrop'],
responsiveStyles: {
small: {
srcset: 'thumbnail'
},
medium: {
srcset: 'thumbnail',
sizes: '50vw'
}
}
}
},
... // Other configurations
}
Summary:
The Nuxt Image Loader module is a powerful tool that simplifies image processing and handling in Nuxt applications. By defining custom image styles and utilizing the GraphicsMagick package, users can automatically resize, rotate, blur, watermark, and crop images based on defined rules. The module seamlessly works with all Nuxt deployment modes and provides support for responsive image handling.