How to use ag-psd - 7 common examples

To help you get started, we’ve selected a few ag-psd examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wonderunit / storyboarder / src / js / importers / psd.js View on Github external
const fs = require('fs')
const readPsd = require('ag-psd').readPsd
const initializeCanvas = require('ag-psd').initializeCanvas

const fromPsdBuffer = buffer => {
  console.log('fromPsdBuffer')

  // setup the PSD reader's initializeCanvas function
  initializeCanvas(
    (width, height) => {
      let canvas = document.createElement('canvas')
      canvas.width = width
      canvas.height = height
      return canvas
    }
  )

  let importable = [
    'reference',
github wonderunit / storyboarder / src / js / window / main-window.js View on Github external
const Guides = require('./guides.js')
const OnionSkin = require('./onion-skin.js')
const Sonifier = require('./sonifier/index.js')
const LayersEditor = require('./layers-editor.js')
const sfx = require('../wonderunit-sound.js')
const keytracker = require('../utils/keytracker.js')
const storyTips = new(require('./story-tips'))(sfx, notifications)
const exporter = require('./exporter.js')
const exporterCommon = require('../exporters/common')
const prefsModule = require('electron').remote.require('./prefs.js')

const boardModel = require('../models/board')

const FileHelper = require('../files/file-helper.js')
const readPsd = require('ag-psd').readPsd;
const initializeCanvas = require('ag-psd').initializeCanvas;

const StsSidebar = require('./sts-sidebar.js')

const pkg = require('../../../package.json')

const sharedObj = remote.getGlobal('sharedObj')

const LAYER_INDEX_REFERENCE = 0
const LAYER_INDEX_MAIN = 1
// onion = 2
const LAYER_INDEX_NOTES = 3
// guides = 4
const LAYER_INDEX_COMPOSITE = 5

const CanvasRecorder = require('../recording/canvas-recorder.js')
const moment = require('moment')
github wonderunit / storyboarder / src / js / exporters / psd.js View on Github external
psd.width = meta.canvas.width > psd.width ? meta.canvas.width : psd.width
    psd.height = meta.canvas.height > psd.height ? meta.canvas.height : psd.height

    id++
  }

  // generate a canvas for the Background layer
  let canvas = document.createElement('canvas')
  canvas.width = psd.width
  canvas.height = psd.height
  var context = canvas.getContext('2d')
  context.fillStyle = 'white'
  context.fillRect(0, 0, canvas.width, canvas.height)
  psd.children[0].canvas = canvas

  return writePsdBuffer(psd)
}
github wonderunit / storyboarder / src / js / files / file-helper.js View on Github external
let getBase64TypeFromPhotoshopFilePath = (filepath, options) => {
  if (!fs.existsSync(filepath)) return null

  initializeCanvas((width, height) => {
        let canvas = document.createElement('canvas');
        canvas.width = width;
        canvas.height = height;
        return canvas;
      });
  
  let psd
  try {
    const buffer = fs.readFileSync(filepath)
    psd = readPsd(buffer)
  } catch(exception) {
    console.error(exception)
    return null
  }

  if(!psd || !psd.children) {
    return;
  }

  let mainCanvas = options.mainCanvas 
  if(!mainCanvas) {
    mainCanvas = document.createElement('canvas')
    mainCanvas.width = psd.width
    mainCanvas.height = psd.height
  }
  let mainContext = mainCanvas.getContext('2d');
github wonderunit / storyboarder / src / js / importers / psd.js View on Github external
return canvas
    }
  )

  let importable = [
    'reference',
    'fill',
    'tone',
    'pencil',
    'ink',
    'notes'
  ]

  let psd
  try {
    psd = readPsd(buffer)
  } catch (err) {
    console.error(err)
  }

  if (!psd) {
    console.warn('PSD is invalid', psd)
    return
  }

  console.log('got psd', psd)

  let numChannelValues = (1 << psd.bitsPerChannel) - 1

  let canvases = { }

  const canvasNameForLayer = name => {
github wonderunit / storyboarder / src / js / files / file-helper.js View on Github external
const path = require('path')
const fs = require('fs')
const readPsd = require('ag-psd').readPsd;
const initializeCanvas = require('ag-psd').initializeCanvas;
const writePsd = require('ag-psd').writePsd;

/**
 * Retrieve an ojbect with base 64 representations of an image file ready for storyboard pane layers.
 *  
 * @param {string} filepath 
 * @param {Object} options
 * @returns {Object} An object with data for notes (optional), reference (optional), and main
 */
let getBase64ImageDataFromFilePath = (filepath, options={ importTargetLayer: 'reference' }) => {
  let { importTargetLayer } = options
  let type = path.extname(filepath).toLowerCase()

  let result = {}
  switch (type) {
    case '.png':
github wonderunit / storyboarder / src / js / files / file-helper.js View on Github external
var whiteBGContext = whiteBG.getContext('2d')
        whiteBGContext.fillStyle = 'white'
        whiteBGContext.fillRect(0, 0, whiteBG.width, whiteBG.height)
        children = [{
          "id": 1,
          "name": "Background",
          "canvas": whiteBG
        }].concat(children)
        let psd = {
          width: psdWidth,
          height: psdHeight,
          imageResources: {layerSelectionIds: [3] },
          children: children
        };

        const buffer = writePsd(psd)
        fs.writeFileSync(psdPath, buffer)
        fulfill()
      })
      .catch(error => {

ag-psd

Library for reading and writing PSD files

MIT
Latest version published 28 days ago

Package Health Score

68 / 100
Full package analysis