How to use psd - 6 common examples

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()) {
github zprodev / psd2json / index.js View on Github external
let outImgDir = '';
  let outJsonDir = '';
  if (typeof options === 'string') {
    outImgDir = options;
    outJsonDir = options;
  } else {
    if (options.outImgDir) {
      outImgDir = options.outImgDir;
    }
    if (options.outJsonDir) {
      outJsonDir = options.outJsonDir;
    }
  }

  // get root node.
  const psdData = psd.fromFile(psdFilePath);
  psdData.parse();
  const rootNode = psdData.tree();

  const queueNodes = [];
  const queueNodesIndex = [];
  const queueNodesName = [];
  const queueNodesStructure = [];

  queueNodes.push(rootNode._children);
  queueNodesIndex.push(0);
  queueNodesName.push(undefined);
  const psdStructure = {
    'group' : []
  };
  queueNodesStructure.push(psdStructure);
github safareli / psd-extractor / lib / psd-extractor.js View on Github external
var LayersfromPathes = R.reduce(function(acc,path){
  var psd = PSD.fromFile(path);
  psd.parse();
  var psdChildren = psd.tree().children()
  return R.concat(acc, psdChildren.map(metaAdder(path)));
}, []);
github zenoamaro / psd-viewer / src / views / application.js View on Github external
async dropFile(event) {
		event.preventDefault();
		this.setState({ loading:true, psd:null });
		let psd = await PSD.fromEvent(event);
		this.setState({ loading:false, psd });
	},

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