npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@floatingpixels/nuxt-imagetools

v0.0.7

Published

Nuxt module for image manipulation and optimization.

Downloads

12

Readme

Nuxt Imagetools

npm version npm downloads License Nuxt

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.

✨  Release Notes

Features

  • ⚡️ Ready-to-use image component
  • 📦 Automatic image optimization
  • 🚀 Output modern formats
  • 🖼 Resize Images
  • 🔍 Image lazy loading
  • 📏 Image aspect ratio
  • 📐 Image cropping
  • 🔒 Remove Image Metadata

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.

Quick Setup

  1. Add 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
  1. Add nuxt-imagetools to the modules section of nuxt.config.ts
export default defineNuxtConfig({
  modules: ['floatingpixels/nuxt-imagetools'],
})

That's it! You can now use imagetools in your Nuxt app ✨

Usage

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.

Configuration

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],
  }
}

formats

Formats to generate

  • default: ['avif', 'webp']
  • type: string[]

See vite-imagetools documentation for more information.

quality

Quality of the generated images (0-100)

  • default: 85
  • type: number

See vite-imagetools documentation for more information.

widths

Resizes the image to be the specified amount of pixels wide. If not given the height will be scaled accordingly.

  • default: [640, 768, 1024, 1280, 1600, 1920]
  • type: number[]

See vite-imagetools documentation for more information.

prefetch

Prefetch 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.

  • default: false
  • type: boolean

See this Nuxt issue for details.