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 🙏

© 2026 – Pkg Stats / Ryan Hefner

vue3-picture-compressor

v1.0.0

Published

Vue 3 component for image compression with build-time optimization

Readme

vue-picture-compressor

Vue 3 component for image optimization with automatic compression at build time.

Features

  • 🖼️ Picture component for Vue 3
  • 🗜️ Automatic image compression at build time (like TinyPNG)
  • ⚙️ Configurable compression percentage
  • 🌐 Automatic WebP version generation
  • 📦 Easy integration with Vite

Installation

npm install vue3-picture-compressor

Requirements

  • Vue 3.x
  • Vite (for using the compression plugin)
  • Node.js 18+ (for building)

Usage

1. Configure Vite Plugin

In your vite.config.js or vite.config.ts:

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { vuePictureCompressor } from 'vue-picture-compressor/vite-plugin'

export default defineConfig({
  plugins: [
    vue(),
    vuePictureCompressor({
      compression: {
        quality: 80, // Quality percentage (0-100, where 100 is no compression)
        jpegQuality: 80, // Quality for JPEG
        pngQuality: [0.6, 0.8], // Quality for PNG [min, max]
        webp: true, // Create WebP versions
        webpQuality: 80, // Quality for WebP
        svgo: true // Optimize SVG
      },
      include: /\.(jpg|jpeg|png|webp|svg)$/i, // Which files to process
      exclude: /node_modules/ // What to exclude
    })
  ]
})

2. Using the Component

Global Registration

import { createApp } from 'vue'
import App from './App.vue'
import VuePictureCompressor from 'vue3-picture-compressor'

const app = createApp(App)
app.use(VuePictureCompressor)
app.mount('#app')

Local Registration

<template>
  <Picture
    src="/images/photo.jpg"
    alt="Image description"
    loading="lazy"
    :webp="true"
  />
</template>

<script setup>
import { Picture } from 'vue3-picture-compressor'
</script>

API

Picture Component

Props

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | src | string | - | Image path (required) | | alt | string | '' | Alternative text | | loading | 'lazy' \| 'eager' | 'lazy' | Loading strategy | | imgClass | string | '' | CSS class for img element | | imgStyle | string \| Record<string, any> | {} | Styles for img element | | webp | boolean | true | Whether to use WebP version |

Events

| Event | Parameters | Description | |-------|------------|-------------| | load | event: Event | Emitted when image loads successfully | | error | event: Event | Emitted when image loading fails |

Vite Plugin Options

CompressionOptions

interface CompressionOptions {
  quality?: number // 0-100, overall quality (100 - no compression)
  jpegQuality?: number // Quality for JPEG (0-100)
  pngQuality?: [number, number] // Quality for PNG [min, max] (0-1)
  webp?: boolean // Whether to create WebP versions
  webpQuality?: number // Quality for WebP (0-100)
  svgo?: boolean // Whether to optimize SVG
}

VuePictureCompressorOptions

interface VuePictureCompressorOptions {
  compression?: CompressionOptions
  include?: string | RegExp | (string | RegExp)[] // Patterns for including files
  exclude?: string | RegExp | (string | RegExp)[] // Patterns for excluding files
}

Examples

Basic Usage

<template>
  <Picture src="/assets/hero.jpg" alt="Hero image" />
</template>

With Settings

<template>
  <Picture
    src="/assets/photo.png"
    alt="Photo"
    :imgClass="'rounded-lg shadow-md'"
    :imgStyle="{ maxWidth: '100%' }"
    loading="eager"
  />
</template>

Event Handling

<template>
  <Picture
    src="/assets/image.jpg"
    alt="Image"
    @load="onImageLoad"
    @error="onImageError"
  />
</template>

<script setup>
const onImageLoad = (event) => {
  console.log('Image loaded', event)
}

const onImageError = (event) => {
  console.error('Image error', event)
}
</script>

Compression Configuration

// vite.config.js
import { vuePictureCompressor } from 'vue-picture-compressor/vite-plugin'

export default defineConfig({
  plugins: [
    vuePictureCompressor({
      compression: {
        quality: 70, // 30% compression
        jpegQuality: 75,
        pngQuality: [0.5, 0.7],
        webp: true,
        webpQuality: 75
      }
    })
  ]
})

How It Works

  1. At build time: The Vite plugin automatically finds all images in your project and compresses them using optimized algorithms (mozjpeg for JPEG, pngquant for PNG).

  2. WebP versions: If enabled, WebP versions of images are automatically created for better performance.

  3. Picture component: Uses the <picture> element with fallback to the original format if the browser doesn't support WebP.

Quality Recommendations

  • 90-100: Minimal compression, high quality (for important images)
  • 70-89: Moderate compression, good quality (recommended)
  • 50-69: Strong compression, acceptable quality (for thumbnails)
  • 0-49: Maximum compression, low quality (not recommended)

License

MIT

Support

If you have questions or suggestions, please create an issue in the GitHub repository.