当前位置:网站首页>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());
}


边栏推荐
- STL string输入输出重载2
- Solve the problem that QQ mail and Thunderbird cannot log in to outlook
- LeetCode_ 77_ combination
- C语言绘图示例-商标徽标
- 01背包面试题系列(一)
- Valid bracket sequence of "Niuke | daily question"
- Robot development -- common simulation software tools
- 2022 National latest fire-fighting facility operator (intermediate fire-fighting facility operator) simulation test questions and answers
- 【机器学习】多标签分类的评价指标与代码实现
- Scrapy关键词 爬虫的简单实现(以新华网和人民网为例)
猜你喜欢

Simple implementation of scrapy keyword crawler (take Xinhuanet and people's network as examples)

Research on Wenhua commodity index

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

【机器学习】多标签分类的评价指标与代码实现

MATLAB(4)函数及文件

Scrapy关键词 爬虫的简单实现(以新华网和人民网为例)

Example of C language painting - progress bar

熟悉NestJS (新手篇)

psd.js 解析PSD文件

Redis Distributed cache - Redis Cluster
随机推荐
Region 性能调优
RMAN abnormal machine recovery error rman-06026 rman-06023
qt 实现遍历文件夹
TiKV 内存参数性能调优
HCIP (7)
MySQL learning notes - paging - table creation - data type
Microcomputer principle and technical interface experiment five basic IO operation temperature control experiment
Property analysis of rotate matrix (forwarding)
C语言绘图示例-分色调图20例
STL string input / output overload 2
延迟加载JS的方式
Valid bracket sequence of "Niuke | daily question"
rman异机恢复报错RMAN-06026 RMAN-06023
Es install IK word breaker
Why does the magnetic variable speed gear reverse?
LeetCode_216_组合总和Ⅲ
Fundamentals of scala (3): operators and process control
MGRE 环境下配置OSPF实验
TiFlash 性能调优
LeetCode刷题——查找和最小的 K 对数字#373#Medium