Commit 959d4db9 authored by rockyl's avatar rockyl

提交

parent 9a995b61
......@@ -83,6 +83,7 @@ async function execute(psdFile, options) {
};
const assets = [];
const imageHashMap = {};
await walkNode(tree, async function (node, parent) {
const {name, x, y, width, height, alpha, visible, origin: {layer, layer: {typeTool, solidColor}}} = node;
......@@ -146,7 +147,7 @@ async function execute(psdFile, options) {
} else {
viewNode.type = 'image';
const uuid = generateUUID();
let uuid = generateUUID();
const ext = '.png';
const imageFilePath = path.join(imagesPath, uuid + ext);
......@@ -157,18 +158,23 @@ async function execute(psdFile, options) {
//await node.origin.saveAsPng(imageFilePath);
if (buffer) {
properties.source = 'asset://' + uuid;
const fileNameHash = hash(buffer);
if (imageHashMap.hasOwnProperty(fileNameHash)) {
uuid = imageHashMap[fileNameHash];
} else {
imageHashMap[fileNameHash] = uuid;
assets.push({
name,
ext,
uuid,
hash: fileNameHash,
});
}
const hashFileName = hash(buffer);
const hashFilePath = path.join(imagesPath, hashFileName + ext);
const hashFilePath = path.join(imagesPath, fileNameHash + ext);
await fs.rename(imageFilePath, hashFilePath);
assets.push({
name,
ext,
uuid,
hash: hashFileName,
});
properties.source = 'asset://' + uuid;
}
}
}
......@@ -211,7 +217,7 @@ function savePng(png, output) {
(async function generate() {
const imagesPath = 'zeroing-demo/images_' + Date.now();
const {view, assets} = await execute('psd/test3.psd', {
const {view, assets} = await execute('psd/test4.psd', {
imagesPath,
});
......
This diff is collapsed.
......@@ -7,7 +7,7 @@ import {toZeroing} from "../../src/index";
(async function generate() {
const imagesPath = 'zeroing-demo/images_' + Date.now();
const {view, assets} = await toZeroing('psd/test3.psd', {
const {view, assets} = await toZeroing('psd/test4.psd', {
imagesPath,
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment