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

svelte-image-input

v1.0.1

Published

Svelte components for loading, resizing, and compressing images into small data URLs for database storage

Downloads

61

Readme

Svelte Image Components demo

Generate small, compressed images that can be stored directly in database fields instead of requiring separate file storage infrastructure. Perfect for profile pictures, avatars, thumbnails, and other small images that need to be stored alongside your data.

This repository contains three Svelte components for working with images:

  1. ImageInput: A component that accepts images via drag and drop, clipboard paste, or by clicking a button to open a file dialog. It then allows you to resize and crop the image before creating a compressed data: URL. It is a combination of the ImageLoader and ImageEncoder components described below.
  2. ImageLoader: A component that allows you to load images via drag and drop, clipboard paste, or by clicking a button to open a file dialog.
  3. ImageEncoder: A component for creating compressed data: URLs from images in real time. You can also move and resize the image before encoding.

It supercedes the svelte-image-encoder component, which is now deprecated.

Installation

npm install svelte-image-input

ImageInput Component

This Svelte component combines the functionality of the ImageEncoder and ImageLoader components, providing an all-in-one solution for loading images, resizing, cropping, and creating data: URLs.

Behavior

When an image is not loaded, the component displays the ImageLoader component, which allows you to load images via drag and drop, clipboard paste, or by clicking a button to open a file dialog.

Once an image is loaded, the component switches to display the ImageEncoder component, which allows you to move and resize the image before encoding it as a data: URL. A close button (X) appears in the top-right corner, allowing you to clear the image and return to the ImageLoader component.

Usage

<script>
	import {ImageInput} from 'svelte-image-input';

	let url = '';
	let src = '';
</script>

<ImageInput
	bind:url
	{src}
	width={256}
	height={256}
	quality={0.5}
	realTime={false}
	crossOrigin={false}
	classes=""
	showCompressedResult={false}
	prefixText="Drop, paste, or"
	buttonText="load an image"
	pasteScope="window"
/>

Props

ImageEncoder Props (passed through to ImageEncoder)

  • src?: string - The source URL of the image to be displayed in the canvas. Defaults to an empty string.
  • url?: string - The data URL of the modified image. Updated on pan and zoom actions. This is an output property, so you must use the bind: directive to bind it to a variable.
  • width?: number - The width of the canvas. Defaults to 256.
  • height?: number - The height of the canvas. Defaults to 256.
  • quality?: number - The image quality (0-1) for the JPEG output. Defaults to 0.5.
  • realTime?: boolean - Whether to update the data URL in real time. Defaults to false.
  • crossOrigin?: boolean - Whether to allow cross-origin images. Defaults to false.
  • classes?: string - A space-separated list of classes to apply to the canvas element.
  • showCompressedResult?: boolean - Whether to show the compressed result. Defaults to false.

ImageLoader Props (passed through to ImageLoader)

  • prefixText?: string - Text displayed before the button in ImageLoader. Default: "Drop, paste, or". See i18n documentation.
  • buttonText?: string - Text displayed on the load button in ImageLoader. Default: "load an image". See i18n documentation.
  • pasteScope?: 'window' | 'component' - Control paste event scope. Default: 'window'. See paste scope documentation.
    • 'window': Paste events anywhere on the page trigger image loading (default)
    • 'component': Paste events only work when the component is focused

ImageLoader Component

Paste, drop or load images in Svelte

This Svelte component allows you to load images via drag and drop, clipboard paste, or by clicking a button to open a file dialog. It handles various input methods and calls a callback with the loaded image's data URL.

Usage

To use the component, add the ImageLoader component to your Svelte app and provide the onImageLoaded callback.

<script>
	import {ImageLoader} from 'svelte-image-input';

	function handleImageLoaded(dataUrl) {
		console.log('Image loaded:', dataUrl);
	}
</script>

<ImageLoader
	onImageLoaded={handleImageLoaded}
	prefixText="Drop, paste, or"
	buttonText="load an image"
	pasteScope="window"
/>

Props

  • onImageLoaded?: (dataUrl: string) => void - Callback function called when an image is loaded. Receives the data URL as a string.
  • prefixText?: string - Text displayed before the button. Default: "Drop, paste, or". See i18n documentation.
  • buttonText?: string - Text displayed on the load button. Default: "load an image". See i18n documentation.
  • pasteScope?: 'window' | 'component' - Control paste event scope. Default: 'window'. See paste scope documentation.
    • 'window': Paste events anywhere on the page trigger image loading (default)
    • 'component': Paste events only work when the component is focused

ImageEncoder Component

Pan, Zoom, and Compress Images in Svelte

This Svelte component allows you to display an image in a canvas, apply pan and zoom actions to it, and create compressed data: URLs from images in real time. The generated data URL is a small, base64-encoded JPEG string that can be stored directly in database string columns, eliminating the need for separate file storage systems or CDN infrastructure.

Key Benefits:

  • Simple storage: Store images directly in your database alongside related data
  • No file system required: No need for S3, cloud storage, or file servers
  • Easy serialization: Data URLs work seamlessly with JSON APIs and can be sent/received in HTTP requests
  • Small file sizes: Configurable quality settings (default 0.5) produce compact images ideal for thumbnails and profile pictures
  • Real-time preview: See the compressed result as you pan and zoom

The component provides a customizable user experience with various configuration options. The original intended use is for profile picture editors, allowing users to resize and crop images before storing them as small data: URLs in database fields.

Usage

<script>
	import {ImageEncoder} from 'svelte-image-input';

	let outputUrl = '';
	let imageUrl = 'https://example.com/image.jpg';
</script>

<ImageEncoder
	bind:url={outputUrl}
	src={imageUrl}
	width={256}
	height={256}
	quality={0.5}
	realTime={false}
	crossOrigin={false}
	classes=""
	showCompressedResult={false}
/>

Props

  • src: string - Required. The source URL of the image to be displayed in the canvas.
  • url: string - Required. The data URL of the modified image. Updated on pan and zoom actions. This is an output property, so you must use the bind: directive to bind it to a variable.
  • quality: number - The image quality (0-1) for the JPEG output. Defaults to 0.5.
  • width: number - The width of the canvas. Defaults to 256.
  • height: number - The height of the canvas. Defaults to 256.
  • realTime: boolean - Whether to update the data URL in real time. Defaults to false.
  • crossOrigin: boolean - Whether to allow cross-origin images. Defaults to false.
  • classes: string - A space-separated list of classes to apply to the canvas element.
  • showCompressedResult: boolean - Whether to show the compressed result. Defaults to false.

Documentation

For advanced usage and customization options, see the following documentation: