agentleFS
Mostafashadow1Mostafashadow1/agent-skills/skills/compressly-image-compression/SKILL.md

compressly-image-compression

Skill0 starsChanged 11 days agoMITView on GitHub

Compress or resize images in the browser before uploading them, using the compressly npm package. Use when a task involves image upload, avatar/profile photo upload, 'file too large' errors, reducing image size, converting to WebP/JPEG, or EXIF rotation in React, Next.js, Vue, Svelte or vanilla JS.

  • Installs packages
  • Sends data out

We split this skill into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Not for: Server-side or build-time image optimization (use sharp, next/image, or your CDN).

    line 16
  2. Very specific:

    Check package.json first. If the project already uses browser-image-compression, compressorjs, keep using it unless the user asks to switch.

    line 24

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Compressly (compressly)

Compressly compresses and resizes images in the browser before upload: max width/height, quality, target file size, EXIF auto-rotation, batch mode with concurrency, and a Web Worker (OffscreenCanvas) path. Zero dependencies, ~2.2 KB gzip, SSR-safe, with an optional React hook.

When to reach for it

  • Users upload photos (avatars, listings, documents, chat images) and you want smaller files before they hit your server or storage.
  • Uploads fail with 'file too large' or are slow on mobile networks.
  • You need a hard size limit, e.g. every image under 500 KB (targetSizeMB: 0.5).
  • You need to compress many files at once without freezing the UI.

Not for: Server-side or build-time image optimization (use sharp, next/image, or your CDN). Lossless archival quality or RAW/HEIC editing.

Setup

npm install compressly

Check package.json first. If the project already uses browser-image-compression, compressorjs, keep using it unless the user asks to switch.

Rules

  • Core functions: compressImage(file, options) returns a File; compressImageWithDetails(file, options) returns { file, originalSize, compressedSize, reductionPercentage, timeTakenMs, dimensions }.
  • Batch: compressImages(files, { concurrency, ...options }) and compressImagesWithDetails. Keep concurrency around 2 to 4 on mobile.
  • Files below maxSizeMB (default 1) are returned unchanged unless forceResize: true.
  • Defaults: maxWidth 1920, maxHeight 1920, quality 0.82, useWorker true, autoRotate true.
  • Output format: mimeType: "image/webp" | "image/jpeg" | "image/png".
  • It needs browser APIs (canvas, File). Call it from event handlers or client components, never during server render. In Next.js App Router, files using compressly/react must start with "use client".
  • React hook: import { useImageCompressor } from "compressly/react" returns { compress, compressMultiple, isCompressing, progress, phase, lastResult, lastBatchResults, error, reset }.
  • Still validate type and size on the server. Client compression is a UX and cost optimization, not a security check.

Examples

Compress before upload

import { compressImage } from "compressly";

async function upload(file: File) {
  const small = await compressImage(file, {
    maxWidth: 1600,
    quality: 0.8,
    targetSizeMB: 0.5,
    mimeType: "image/webp",
  });
  const body = new FormData();
  body.append("photo", small);
  await fetch("/api/upload", { method: "POST", body });
}

React hook

"use client";
import { useImageCompressor } from "compressly/react";

export function AvatarInput({ onReady }: { onReady: (f: File) => void }) {
  const { compress, isCompressing, progress } = useImageCompressor({ maxWidth: 512, quality: 0.85 });
  return (
    <>
      <input
        type="file"
        accept="image/*"
        disabled={isCompressing}
        onChange={async (e) => {
          const f = e.target.files?.[0];
          if (f) onReady((await compress(f)).file);
        }}
      />
      {isCompressing && <progress value={progress} max={100} />}
    </>
  );
}

API

  • compressImage(file, CompressOptions): Promise<File>
  • compressImageWithDetails(file, CompressOptions): Promise<CompressResult>
  • compressImages(files, BatchCompressOptions), compressImagesWithDetails(...) with concurrency, onFileComplete, onBatchProgress.
  • CompressOptions: maxSizeMB (1), targetSizeMB, maxWidth (1920), maxHeight (1920), quality (0.82), mimeType, useWorker (true), autoRotate (true), forceResize (false), onProgress(percent, phase).
  • Helpers: calculateDimensions, loadImageWithExif, isWorkerSupported.
  • compressly/react: useImageCompressor(options).

Docs: https://compress-ly.vercel.app/

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.