Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep the document width and height , when exporting a layer (animations) #70

Open
gcmartijn opened this issue Dec 6, 2022 · 0 comments

Comments

@gcmartijn
Copy link

H!

Maybe someone can use this in the future.
I have made some animations inside photoshop, within the same document.
each layer is a frame, and have different sizes.

When you export the layer, then you get different sizes.
With this code, you will keep the document sizes, and the correct layer position in the document.
So you can replay the animation again, inside a game or whatever.

import * as fs from "fs"
import Psd from "@webtoon/psd"
import { createCanvas, createImageData } from 'canvas'

const psdData = fs.readFileSync("talk-sideways.psd")
const psdFile = Psd.parse(psdData.buffer)

    let layerPixelData = await layer.composite()

    const canvas = createCanvas(psdFile.width, psdFile.height)
    const ctx = canvas.getContext('2d')

    const image = createImageData(layerPixelData, layer.width, layer.height)
    ctx.putImageData(image, layer.left, layer.top)

    const out = fs.createWriteStream('out.png')
    const stream = canvas.createPNGStream()
    stream.pipe(out)
    out.on('finish', () => console.log('The PNG file was created.'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant