All Projects → webtoon → psd

webtoon / psd

Licence: MIT license
Blazing fast, zero-dependency PSD parser for the web and Node.js

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to psd

Libqpsd
PSD (Photoshop Document) & PSB (Photoshop Big) Plugin for Qt/C++ (Qt4/Qt5)
Stars: ✭ 90 (-83.61%)
Mutual labels:  photoshop, psd
Psd.rb
Parse Photoshop files in Ruby with ease
Stars: ✭ 3,092 (+463.21%)
Mutual labels:  photoshop, psd
Psd Tools
Python package for reading Adobe Photoshop PSD files
Stars: ✭ 646 (+17.67%)
Mutual labels:  photoshop, psd
Ag Psd
Javascript library for reading and writing PSD files
Stars: ✭ 135 (-75.41%)
Mutual labels:  photoshop, psd
Psd Templates Requirements
Требования, пожелания и рекомендации к PSD (и не только) макетам
Stars: ✭ 140 (-74.5%)
Mutual labels:  photoshop, psd
Psd2unityimporter
An advanced PSD importer tool for Unity
Stars: ✭ 155 (-71.77%)
Mutual labels:  photoshop, psd
Psdinfo
Inspect PSD files from the command line
Stars: ✭ 144 (-73.77%)
Mutual labels:  photoshop, psd
psd2svg
PSD to SVG converter.
Stars: ✭ 40 (-92.71%)
Mutual labels:  photoshop, psd
lut
color lookup tables (LUTs) for color grading
Stars: ✭ 84 (-84.7%)
Mutual labels:  photoshop
photoshop-react-redux-ramda
🎨😱💀⚛️
Stars: ✭ 24 (-95.63%)
Mutual labels:  photoshop
photoshop-scripts
Photoshop Scripts for the TinyPNG & TinyJPG Photoshop plugin
Stars: ✭ 43 (-92.17%)
Mutual labels:  photoshop
favicon
🖼 An attempt to capture all possible favicons for a web project.
Stars: ✭ 17 (-96.9%)
Mutual labels:  photoshop
srcset.sh
A command line script that generates multiple responsive versions of an image at width breakpoints -- 320,480,640,768,960,1024,1280,1440 pixels wide -- that match common Mobile and widescreen desktop/laptop viewports using Imagemagick's convert utility and outputs the needed <img/> tag
Stars: ✭ 20 (-96.36%)
Mutual labels:  photoshop
cyan
Cyan Color Converter
Stars: ✭ 68 (-87.61%)
Mutual labels:  psd
multiverse
Adobe Photoshop scripts for making generative art
Stars: ✭ 21 (-96.17%)
Mutual labels:  photoshop
ovid-editor
Adobe panel providing the most advanced scripting environment possible -- Typescript, app DOM autocomplete, full I/O features and more
Stars: ✭ 43 (-92.17%)
Mutual labels:  photoshop
whatsapp-jpeg-repair
A handy tool to fix jpeg files downloaded from WhatsApp and prevent errors upon opening these files in Adobe Photoshop.
Stars: ✭ 30 (-94.54%)
Mutual labels:  photoshop
psd-to-sketch-converter
Convert PSD to Sketch for free
Stars: ✭ 42 (-92.35%)
Mutual labels:  photoshop
C-Sharp-Learning-Journey
Some of the projects i made when starting to learn c#, winfroms and wpf
Stars: ✭ 95 (-82.7%)
Mutual labels:  photoshop
FreeMote
Managed Emote/PSB tool libs.
Stars: ✭ 150 (-72.68%)
Mutual labels:  psb

@webtoon/psd

Package on NPM Minified size

A lightweight Adobe Photoshop .psd/.psb file parser in typescript with zero-dependency for web browsers and NodeJS

@webtoon/psd is a fast, lightweight parser for Adobe Photoshop PSD/PSB files. It uses standard (ES2015+) features and can be used both in web browsers and in Node.js. It pulls in zero dependencies, making it smaller (~25 KiB minified) than other PSD parsers (ag-psd: 139 KiB, PSD.js: 443 KiB).

Browser Support

Chrome Firefox Safari Edge Node
38 20 10.1 79 12

*Internet Explorer is not supported

Installation

$ npm install @webtoon/psd

Benchmarks

You can run benchmarks for @webtoon/psd in your browser.

Features

Supported

  • Support large format (.psb)
  • Image / Layer information (size, offset, etc.)
  • Image / Layer pixel data
  • Unicode layer names
  • Image / Layer opacity
  • Text layers string value
  • Guides
  • Slices

🚧 Work in progress

  • Layer effects (shadow, overlays, etc.)

Unsupported

  • Photoshop metadata not directly related to the image

Usage

@webtoon/psd is provided as a pure ECMAScript module.

Web Browsers

Check out the live demo and the the source for web browser.

@webtoon/psd must be bundled with a bundler such as Webpack or Rollup.

@webtoon/psd reads a PSD file as an ArrayBuffer. You can use FileReader or File to load a PSD file:

import Psd from "@webtoon/psd";

const inputEl: HTMLInputElement = document.querySelector("input[type='file']");
inputEl.addEventListener("change", async () => {
  const file = inputEl.files[0];

  const result = await file.arrayBuffer();
  const psdFile = Psd.parse(result);

  const canvasElement = document.createElement("canvas");
  const context = canvasElement.getContext("2d");
  const imageData = new ImageData(
    psdFile.composite(),
    psdFile.width,
    psdFile.height
  );

  canvasElement.width = psdFile.width;
  canvasElement.height = psdFile.height;

  context.putImageData(imageData, 0, 0);
  document.body.append(canvasElement);
});

For performance, we recommend parsing PSD files in a Web Worker rather than the main thread.

NodeJS

@webtoon/psd does not support the Node.js Buffer. You must explicitly supply the underlying ArrayBuffer.

import * as fs from "fs";
import Psd from "@webtoon/psd";

const psdData = fs.readFileSync("./my-file.psd");
// Pass the ArrayBuffer instance inside the Buffer
const psdFile = Psd.parse(psdData.buffer);

Since @webtoon/psd is provided as an ES module, you must use dynamic import() or a bundler to run it in CommonJS code:

const Psd = await import("@webtoon/psd");

API Docs

This library provides the Psd class as the default export.

Opening a file

Psd.parse(ArrayBuffer) takes an ArrayBuffer containing a PSD or PSB file and returns a new Psd object.

const psdFile = Psd.parse(myBuffer);

Traversing layers

A Psd object contains a tree of Layer and Group (i.e. layer group) objects.

  • The Psd object provides a children property, which is an array of top-level Layers and Groups.
  • Each Group object provides a children property, which is an array of Layers and Groups that belong immediately under the current layer group .
import Psd, {Group, Layer, Node} from "@webtoon/psd";

// Recursively traverse layers and layer groups
function traverseNode(node: Node) {
  if (node instanceof Group) {
    for (const child of node.children) {
      traverseNode(child);
    }
  } else if (node instanceof Layer) {
    // Do something with layer
  } else {
    throw new Error("Invalid node type");
  }
}

for (const node of psdFile.children) {
  traverseNode(node);
}

The Psd object also provides the layers property, which is an array of all Layers in the image (including nested).

for (const layer of psdFile.layers) {
  doSomething(layer);
}

Retrieving image data

Use Psd.prototype.composite() and Layer.prototype.composite() to retrieve the pixel information for the entire image or an individual layer.

// Extract the pixel data of the entire image
pixelData = psd.composite();

// Extract the pixel data of a layer, with all layer and layer group effects applied
// (currently, only the opacity is supported)
layerPixelData = layer.composite();

// Extract the pixel data of a layer, with only the layer's own effects applied
layerPixelData = layer.composite(true, false);

// Extract the pixel data of a layer, without any effects
layerPixelData = layer.composite(false);

License

@webtoon/psd is released under the MIT license.

Copyright 2021-present NAVER WEBTOON

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
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].