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

photopea-cli

v0.1.0

Published

edit images from the terminal using photopea, driven by playwright-cli

Downloads

30

Readme

photopea-cli

Edit images from the terminal using Photopea, driven by playwright-cli.

photopea-cli boots a real Photopea instance inside a headless browser, feeds it your image through the Photopea live-messaging API, runs edits with the Photoshop-compatible scripting interface (app.activeDocument...), and writes the exported result back to disk. It supports every format Photopea can read (PSD, AI, XD, Sketch, PDF, RAW, PNG, JPG, SVG, ...) and export (PNG, JPG, WEBP, GIF, PSD, PDF, SVG, ...).

Requirements

  • Node.js 20+

  • playwright-cli installed globally and on PATH:

    npm install -g playwright-cli
  • an internet connection (photopea.com is loaded live)

Install

npm install -g photopea-cli

Usage

photopea-cli convert <input> [output] [options]
photopea-cli edit <input> [output] [options]
photopea-cli run <input> <output> --script "js code" | --script-file file.js
photopea-cli info <input>
photopea-cli layers <input>
photopea-cli probe
photopea-cli close

Options

| flag | description | | --- | --- | | -o, --out <path> | output path (- writes bytes to stdout) | | -q, --quality <0..1> | jpg / webp quality | | -f, --format <fmt> | output format: png jpg webp gif psd pdf svg bmp tiff ico | | --resize <WxH> | resize image; either side may be empty (800x, x600) to keep aspect | | --canvas <WxH> | resize canvas without scaling content | | --rotate <deg> | rotate canvas | | --flip <h\|v> | flip canvas horizontally / vertically | | --crop <x,y,w,h> | crop to a rectangle | | --invert | invert colors of the active layer | | --grayscale | convert document to grayscale | | --script <js> | custom Photopea script (with run) | | --script-file <path> | file containing a custom Photopea script (with run) | | --timeout <ms> | per-step timeout (default 120000) | | --keep | keep the browser session alive after finishing | | --quiet | suppress progress logs |

Input - reads the image from stdin.

Examples

Convert a PSD to PNG:

photopea-cli convert design.psd design.png

Resize and recompress:

photopea-cli edit cat.jpg small.jpg --resize 400x --quality 0.8

Rotate, flip and grayscale:

photopea-cli edit cat.jpg out.png --rotate 90 --flip h --grayscale

Inspect a document:

photopea-cli info design.psd
photopea-cli layers design.psd

Run an arbitrary Photopea script — the full Photoshop-style document model is available via app:

photopea-cli run cat.jpg out.png --script "
  d.resizeCanvas('600px', '600px');
  app.echoToOE('layers: ' + d.layers.length);
"

In custom scripts, app is the Photopea application object and d is pre-bound to app.activeDocument. Use app.echoToOE(str) to log strings back to the CLI (they appear as script: ... progress lines), and app.activeDocument.saveToOE(format) is called for you afterwards using the requested output format.

Note: Photopea's script engine aborts on any uncaught JavaScript exception, which the CLI reports as a timeout. Keep scripts exception-free: guard unset properties and avoid throw.

Draw programmatically (the full Photoshop-style DOM is available):

photopea-cli run cat.jpg painted.png --script "
  d.selection.select([[40,40],[240,40],[240,240],[40,240]]);
  var c = new SolidColor();
  c.rgb.red = 255; c.rgb.green = 0; c.rgb.blue = 0;
  d.selection.fill(c);
  d.selection.deselect();
  var t = d.artLayers.add();
  t.kind = LayerKind.TEXT;
  t.textItem.contents = 'hello';
  t.textItem.size = 60;
"

Pipe through:

cat cat.jpg | photopea-cli convert - - --format webp > cat.webp

Sessions

Every run uses the shared headless browser session photopea-cli (via playwright-cli -s photopea-cli) and gets a freshly reloaded Photopea, so runs are hermetic and never affected by previous documents. By default the browser is closed when the run finishes; pass --keep to leave it running and save the browser boot time (~2s) on subsequent commands (Photopea itself is still reloaded per run). To shut everything down:

photopea-cli close

How it works

  1. A local throwaway HTTP server (bound to 127.0.0.1, random port) serves a minimal bridge page that embeds photopea.com in an iframe.
  2. The image is base64-chunked into the page through playwright-cli eval, rebuilt as an ArrayBuffer and delivered to Photopea via postMessage (no CORS issues, no file uploads).
  3. Edit operations are compiled into a Photoshop-compatible script and executed inside Photopea.
  4. The document is exported with Document.saveToOE(format); the resulting ArrayBuffer is read back out in chunks and written to disk.

Because it uses a real Photopea, anything it can do is a one-line --script away: layer manipulation, text edits, filters, batch conversion between exotic formats, and more.

License

MIT