All Projects → ElMassimo → vite-plugin-image-presets

ElMassimo / vite-plugin-image-presets

Licence: MIT license
🖼 Image Presets for Vite.js apps

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
Vue
7211 projects
HTML
75241 projects

Projects that are alternatives of or similar to vite-plugin-image-presets

vite-plugins
🌱 为社区尽一份绵薄之力
Stars: ✭ 63 (-61.59%)
Mutual labels:  vitejs, vite-plugin
vite-plugin-theme-preprocessor
css theme preprocessor plugin for vite
Stars: ✭ 144 (-12.2%)
Mutual labels:  vitejs, vite-plugin
vite-plugin-ssr
Like Next.js / Nuxt but as do-one-thing-do-it-well Vite plugin.
Stars: ✭ 1,703 (+938.41%)
Mutual labels:  vitejs, vite-plugin
vite-plugin-environment
Easily expose environment variables in Vite.js
Stars: ✭ 57 (-65.24%)
Mutual labels:  vitejs, vite-plugin
vite-plugin-webfont-dl
⚡ Webfont Download Vite Plugin - Make your Vite site load faster
Stars: ✭ 69 (-57.93%)
Mutual labels:  vitejs, vite-plugin
trailing-slash-guide
Understand and fix your static website trailing slash issues!
Stars: ✭ 255 (+55.49%)
Mutual labels:  ssg
admin-one-vue-tailwind
Free Vue.js 3.x Tailwind 3.x admin dashboard template with dark mode. Vite builds. Pinia state. Laravel integration available
Stars: ✭ 742 (+352.44%)
Mutual labels:  vitejs
photosheet
A photo sheet generator
Stars: ✭ 25 (-84.76%)
Mutual labels:  ssg
osbuild
Build-Pipelines for Operating System Artifacts
Stars: ✭ 95 (-42.07%)
Mutual labels:  images
personal-website
Personal website – made with Next.js, Preact, MDX, RMWC, & Vercel
Stars: ✭ 16 (-90.24%)
Mutual labels:  ssg
lambda-resize-image
An AWS Lambda Function to resize images automatically with API Gateway and S3 for imagemagick tasks. When an image is called on AWS Api Gateway, this package will resize it and send it to the S3.
Stars: ✭ 56 (-65.85%)
Mutual labels:  sharp
vite-plugin-vue-gql
⚡ GraphQL Tags for your Vue SFC ⚡
Stars: ✭ 188 (+14.63%)
Mutual labels:  vitejs
ColorVectorSpace.jl
Treat colors as if they are n-vectors for the purposes of arithmetic
Stars: ✭ 28 (-82.93%)
Mutual labels:  images
adorable-css
Rapid On-Demand Atomic CSS Framework
Stars: ✭ 131 (-20.12%)
Mutual labels:  vite-plugin
use-images-loaded
🖼️ Returns true once all the images inside a container are loaded
Stars: ✭ 82 (-50%)
Mutual labels:  images
Floral
Minimal design gallery app for Android.
Stars: ✭ 23 (-85.98%)
Mutual labels:  images
etiketai
Etiketai is an online tool designed to label images, useful for training AI models
Stars: ✭ 63 (-61.59%)
Mutual labels:  images
vite-plugin-sleep
a vite plugin you never need. slow devServer and slow HMR.
Stars: ✭ 77 (-53.05%)
Mutual labels:  vite-plugin
vite-bundle
Integration with your Symfony app & Vite
Stars: ✭ 56 (-65.85%)
Mutual labels:  vitejs
wordpress-scaffold
The scaffold for GRRR's WordPress Pro setup.
Stars: ✭ 16 (-90.24%)
Mutual labels:  ssg


vite-plugin-image-presets

Image Presets for Vite.js apps


This Vite plugin allows you to define presets for image processing using Sharp, allowing you to optimize, resize, and process images consistently and with ease.

Demo 🖼

Installation 💿

npm install -D vite-plugin-image-presets # pnpm, yarn

Configuration ⚙️

Add it to your plugins in vite.config.ts

import { defineConfig } from 'vite'
import imagePresets, { widthPreset } from 'vite-plugin-image-presets'

export default defineConfig({
  plugins: [
    imagePresets({
      thumbnail: widthPreset({
        class: 'img thumb',
        loading: 'lazy',
        widths: [48, 96],
        formats: {
          webp: { quality: 50 },
          jpg: { quality: 70 },
        },
      }),
    }),
  ],
})

Usage 🚀

Use the preset query parameter to obtain an array of source and img attrs:

import thumbnails from '~/images/logo.jpg?preset=thumbnail'

expect(thumbnails).toEqual([
  {
    type: 'image/webp',
    srcset: '/assets/logo.ffc730c4.webp 48w, /assets/logo.1f874174.webp 96w',
  },
  {
    type: 'image/jpeg',
    srcset: '/assets/logo.063759b1.jpeg 48w, /assets/logo.81d93491.jpeg 96w',
    src: '/assets/logo.81d93491.jpeg',
    class: 'img thumb',
    loading: 'lazy',
  },
])

You can also use the src and srcset query parameters for direct usage:

import srcset from '~/images/logo.jpg?preset=thumbnail&srcset'
import src from '~/images/logo.jpg?preset=thumbnail&src'

expect(srcset).toEqual('/assets/logo.063759b1.jpeg 48w, /assets/logo.81d93491.jpeg 96w')
expect(src).toEqual('/assets/logo.81d93491.jpeg')

Check the example for additional usage information and different preset examples, or see it live.

Documentation 📖

Additional usage documentation coming soon.

In the meantime, check the @islands/images module for îles.

Acknowledgements

  • sharp: High performance Node.js image processing
  • vite-imagetools: The middleware used in development is based on this nice library.

The hdPreset is based on the following article by Jake Archibald:

License

This library is available as open source under the terms of the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].