当前位置:网站首页>psd. JS parsing PSD file
psd. JS parsing PSD file
2022-07-19 12:11:00 【Yangge landing】
List of articles
Preface
Make a note of psd.js analysis PSD file
One 、vue Import psd.js
npm install --save psd.js
Details refer to github,psd.js: https://github.com/meltingice/psd.js
Two 、 analysis psd file
Use el-upload Upload psd file
<template>
<div>
<el-upload
:auto-upload="false"
:on-change="parsePSD"
class="upload-demo"
drag
action=""
>
<i class="el-icon-upload" />
<div class="el-upload__text"> Click Add or drag and drop PSD file </div>
</el-upload>
</div>
</template>
<script>
// introduce psd.js
import PSD from 'psd.js'
export default {
methods: {
parsePSD(file) {
// psd file
var url = URL.createObjectURL(file.raw)
// analysis psd file
PSD.fromURL(url).then(psd => {
console.log(psd)
// psd Background image
const l_background = psd.image.toBase64()
// Get layer data
const childrens = psd.tree().children()
childrens.forEach(item => {
if (item._children.length > 0) {
// Child node layer
const _child = item._children
_child.forEach(i => {
const typeTool = i.get('typeTool')
if (typeof typeTool !== 'undefined') {
// Get word spacing
if (typeof (typeTool.styles().Tracking) !== 'undefined') {
console.log(typeTool.styles().Tracking[0])
}
}
// Get sub layer pictures
const child_image = i.layer.image.toBase64()
})
}
})
// Export layer data
var exportData = psd.tree().export()
const _export_childrens = exportData.children
for (var i = 0; i < _export_childrens.length; i++) {
// Top level layer / Folder
const name = _export_childrens[i].name
var i_child = _export_childrens[i].children
if (typeof (i_child) !== 'undefined') {
for (var j = 0; j < i_child.length; j++) {
// Sublayer data
console.log(i_child[j])
}
}
}
})
}
}
}
</script>
3、 ... and 、psd Method
1.psd Background image to base64 Format
PSD.fromURL(url).then(psd => {
console.log(psd.image.toBase64())
}
2. Get all the direct child nodes of the node
PSD.fromURL(url).then(psd => {
console.log(psd.tree().children())
}
_children For all child node layers 
3. The text layer gets the word spacing
PSD.fromURL(url).then(psd => {
const parent = psd.tree().children()
const typeTool = parent._chilren[0].get('typeTool')
console.log(typeTool.styles().Tracking[0])
}
4. Sub layer background
PSD.fromURL(url).then(psd => {
const parent = psd.tree().children()
const children = parent._chilren[0]
console.log(children.layer.image.toBase64())
}
5. Derived data
PSD.fromURL(url).then(psd => {
console.log(psd.tree().export());
}


边栏推荐
- zabbix-snmp监控
- C# . Net Yunnan rural credit national secret signature (SM2) brief analysis
- Research and implementation of 5g network Slicing Based on AI intelligent correlation technology
- Focus on the new track of green development - release of MAPGIS intelligent environmental protection solution
- Conversion between Swift binary data and hexadecimal string
- Robot development -- common simulation software tools
- 01背包面试题系列(一)
- Mysql学习笔记-分页-表的创建-数据类型
- STL string input / output overload
- Example of C language drawing - 20 examples of chromatic diagram
猜你喜欢

Project construction depends on people, and success depends on people!

The underlying principle of file operation (inode and hard and soft links, time attributes of files)

LeetCode_ 17_ Letter combination of telephone number

HCIP (7)

Wechat applet cloud development 1 - Database

Lychee sound quality high fidelity AI noise reduction technology sharing

MGRE 环境下配置OSPF实验

Enabling cities to "plan, build, operate, manage and serve" -- MAPGIS CIM platform explores "cim+" multi scenario applications

数据库每日一题---第25天:银行账户概要 II

2022-07-07:Spire.Office 7.7.2 for net 闪亮登场
随机推荐
[machine learning] evaluation index and code implementation of multi label classification
HCIP(4)
MySQL learning notes - paging - table creation - data type
项目建设,谋事在人,成事亦在人!
Mysql学习笔记-分页-表的创建-数据类型
2022-07-07:Spire.Office 7.7.2 for net 闪亮登场
Example of C language drawing - 20 examples of chromatic diagram
Research on Wenhua commodity index
TiKV 线程池性能调优
延迟加载JS的方式
Nature | the carbon sequestration rate of groundwater is similar to that of oligotrophic marine system
SQL盲注详解
STL string input / output overload 1
STL string input / output overload
解决:code ERESOLVE:ERESOLVE could not resolve 的报错问题
QT learning diary 17 - QT database
Fundamentals of scala (3): operators and process control
Flink
The adaptation of go language under windows10:vscode
How to delay loading JS