How to use the psd.open function in psd

To help you get started, we’ve selected a few 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 zswang / h5psd / src / h5psd.js View on Github external
function build(filename, argv) {
  filename = path.resolve('', filename || '');
  if (!fs.existsSync(filename)) {
    console.warn(
      colors.blue('File "%s" not exists.'), filename
    );
    return;
  }

  // 处理默认值
  argv = argv || {};

  var output = argv.output || path.dirname(filename);
  var images = argv.images || 'images';

  return psd.open(filename).then(function (context) {
    mkdirp.sync(path.join(output, images)); // 确保输出目录存在

    var tree = context.tree();
    var treeInfo = tree.export();
    var h5 = {
      name: path.basename(filename),
      width: treeInfo.document.width,
      height: treeInfo.document.height,
      layers: []
    };

    // var promise = [];
    var layers = h5.layers;
    var md5dict = {};
    var promises = [];
github kartsims / psd-cli / bin / psd.js View on Github external
console.log("\nProcessing %s ...", filepath);

    try {
      var buffer = readChunk.sync(filepath, 0, 262);
      var type = fileType(buffer).ext;
      if (type != 'psd') {
        console.log(chalk.red.bold("%s is not a PSD file, type detected : %s"), filepath, type);
        return cb();
      }
    } catch (e) {
      console.log(chalk.red.bold("%s could not be opened with PSD library"), filepath);
      return cb();
    }

    var psdPromise = PSD.open(filepath);
    var asyncTasks = [];

    // convert file to PNG
    if (program.convert || program.open) {
      asyncTasks.push(function(cb) {
        convertFile(filepath, psdPromise, cb);
      });
    }
    // extract text data
    if (program.text) {
      asyncTasks.push(function(cb) {
        extractTextFromFile(filepath, psdPromise, cb);
      });
    }

    async.series(asyncTasks, cb);
github zswang / h5psd / lib / h5psd.js View on Github external
colors.blue('PSD file "%s" not exists.'), filename
    );
    return;
  }
  template = argv.template || path.join(__dirname, '../tpl/page.html');
  if (!fs.existsSync(template)) {
    console.warn(
      colors.blue('Template file "%s" not exists.'), template
    );
    return;
  }
  // 处理默认值
  argv = argv || {};
  var output = argv.output || path.dirname(filename);
  var images = argv.images || 'images';
  return psd.open(filename).then(function (context) {
    mkdirp.sync(path.join(output, images)); // 确保输出目录存在
    var tree = context.tree();
    var treeInfo = tree.export();
    var h5 = {
      name: path.basename(filename),
      width: treeInfo.document.width,
      height: treeInfo.document.height,
      layers: []
    };
    // var promise = [];
    var layers = h5.layers;
    var md5dict = {};
    var promises = [];
    var descendants = tree.descendants();
    descendants.forEach(function (node, index) {
      if (node.isGroup() || node.hidden()) {

psd

A general purpose Photoshop file parser.

MIT
Latest version published 3 years ago

Package Health Score

57 / 100
Full package analysis

Popular psd functions