
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@floatingpixels/nuxt-imagetools
Advanced tools
Nuxt module for image manipulation and optimization. You simply put high-quality images in the assets folder, and import them in your pages and components. Optimized renditions are automatically generated during build-time, and an image component automatically uses the right, optimized image for each browser and resolution in runtime.
This module is a wrapper around sharp and imagetools.
Optimizing your images by hand is a tedious and error-prone process: Opening the image in Photoshop, naming and exporting each image individually, and then reference everything correctly in the HTML. This is where imagetools comes to the rescue: simply reference your image in code, specify the needed transformations and imagetools will take care of the rest! All this happens during build-time, so your users will only download the optimized images.
This module optimizes images offline during built-time, providing an alternative to Nuxt Image and other modules, which mainly rely on CDNs and online optimization.
nuxt-imagetools to your project# Using pnpm
pnpm add -D floatingpixels/nuxt-imagetools
# Using yarn
yarn add --dev floatingpixels/nuxt-imagetools
# Using npm
npm install --save-dev floatingpixels/nuxt-imagetools
nuxt-imagetools to the modules section of nuxt.config.tsexport default defineNuxtConfig({
modules: ['floatingpixels/nuxt-imagetools'],
})
That's it! You can now use imagetools in your Nuxt app ✨
To get started quickly, a sensible default configuration is provided. It generates webp and avif renditions in common browser resolutions for each image, and automatically generates a sourcemap that can be used in the provided Image component. This component selects the right image for each browser and resolution using the standard HTML picture element.
<script setup lang="ts">
// simply import your images and add ?imagetools to the end of the path
import pic_1 from '~/assets/high_quality_image.png?imagetools'
</script>
<template>
<div>
<Image
:picture="pic_1"
alt="Picture One"
sizes="(min-width: 1280px) 50vw, 100vw"
/>
</div>
</template>
The sizes attribute is used to specify the size of the image at different screen sizes. The browser will select the right image for the current screen size and resolution based on what you define here. The picture attribute is used to specify the image to be displayed. The alt attribute is used to specify the alternative text for the image.
The defaults are trying to cover the most common use case. You can also customize the defaults, or generate different formats, sizes, aspect ratios and outputs and use them in whatever way you like. This is how to change the module defaults in nuxt.config.ts:
export default defineNuxtConfig({
// ...
imagetools: {
formats: ['avif', 'webp'],
quality: 85,
widths: [640, 768, 1024, 1280, 1600, 1920],
}
}
formatsFormats to generate
['avif', 'webp']string[]See vite-imagetools documentation for more information.
qualityQuality of the generated images (0-100)
85numberSee vite-imagetools documentation for more information.
widthsResizes the image to be the specified amount of pixels wide. If not given the height will be scaled accordingly.
[640, 768, 1024, 1280, 1600, 1920]number[]See vite-imagetools documentation for more information.
prefetchPrefetch all images - setting to false prevents media to be included in the header as prefetch. If set to true Chrome loads ALL assets, including all renditions of assets that are not used, which is NOT what you want under normal circumstances.
falsebooleanSee this Nuxt issue for details.
FAQs
Nuxt module for image manipulation and optimization.
We found that @floatingpixels/nuxt-imagetools demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.