透過網頁讀取PSD後,依圖層輸出PNG檔案
在前面介紹過網頁可以讀取PSD檔案並擷取到該檔案的資訊,接著我們會希望能透過網頁上傳PSD檔之後,依照圖層來輸出圖片,同樣是利用PSD.js來輔助進行,可以透過我們製作的範例頁面來進行輸出測試。
預設輸出效果
透過PSD.js可將PSD內的各圖層輸出成PNG圖檔,亦可轉成Base 64圖檔格式,惟輸出時每個圖檔的尺寸並不會根據整體PSD檔大小來配置。




<!DOCTYPE html> <html> <head> <title>psd.js image example</title> <style type="text/css"> body, html { padding: 0; margin: 0; } #dropzone { width: 500px; height: 100px; border: 1px #ababab dashed; margin: 50px auto; } #dropzone p { text-align: center; line-height: 100px; margin: 0; padding: 0; } #image { text-align: center; } </style> <script type="text/javascript" src="psd.min.js"></script> </head> <body> <div id="dropzone"> <p>Drop PSD here</p> </div> <div id="image"></div> <pre id="data"></pre> <script type="text/javascript"> (function () { const PSD = require('psd'); document.getElementById('dropzone').addEventListener('dragover', onDragOver, true); document.getElementById('dropzone').addEventListener('drop', onDrop, true); function onDragOver(e) { e.stopPropagation(); e.preventDefault(); e.dataTransfer.dropEffect = 'copy'; } function onDrop(e) { e.stopPropagation(); e.preventDefault(); PSD.fromEvent(e).then(function (psd) { for (var i = 0; i < psd.layers.length; i ++){ document.getElementById('image').appendChild(psd.layers[i].image.toPng()); } }); } }()); </script> </body> </html>
依照整體PSD配置進行輸出
我們希望讓每個圖片在輸出後能保時相同的尺寸,也就是依照PSD的畫布大小來輸出每一張圖檔,但在原生PSD.js中並不具備這樣的功能,於是我們透過下述的方式來達成:
- 擷取PSD資訊並將圖檔轉為Base 64格式
- 產生與PSD尺寸大小相同的HTML Canvas
- 將產生的Base 64圖檔,依照原始位置放入Canvas中
- 將Canvas轉成PNG圖檔




可以參考我們製作的範例頁面
<!DOCTYPE html> <html> <head> <title>psd.js image example</title> <style type="text/css"> body, html { padding: 0; margin: 0; } #dropzone { width: 500px; height: 100px; border: 1px #ababab dashed; margin: 50px auto; } #dropzone p { text-align: center; line-height: 100px; margin: 0; padding: 0; } #image { text-align: center; } </style> <script type="text/javascript" src="psd.min.js"></script> </head> <body> <div id="dropzone"> <p>Drop PSD here</p> </div> <div id="image"></div> <pre id="data"></pre> <script type="text/javascript"> (function () { const PSD = require('psd'); document.getElementById('dropzone').addEventListener('dragover', onDragOver, true); document.getElementById('dropzone').addEventListener('drop', onDrop, true); function onDragOver(e) { e.stopPropagation(); e.preventDefault(); e.dataTransfer.dropEffect = 'copy'; } function onDrop(e) { e.stopPropagation(); e.preventDefault(); PSD.fromEvent(e).then(function (psd) { const PSDWidth = psd.tree().width; const PSDHeight = psd.tree().height; for (var i = 0; i < psd.layers.length; i ++){ const img = new Image(); img.src = psd.layers[i].image.toBase64(); console.log(psd); const layerWidth = psd.layers[i].width; const layerHeight = psd.layers[i].height; const layerLeft = psd.layers[i].left; const layerTop = psd.layers[i].top; const canvas = document.createElement("canvas"); canvas.setAttribute('class', "canvas"); canvas.width = PSDWidth; canvas.height = PSDHeight; console.log("canvas :", canvas); img.onload = function(){ canvas.getContext("2d").drawImage(img, layerLeft, layerTop, layerWidth, layerHeight); document.getElementById('image').appendChild(canvas); } } }); } }()); </script> </body> </html>
PSD檔案輸出限制
1. 無法輸出帶有效果的圖片
在PSD中我們可能會針對圖層套用一些效果,例如:陰影、光暈、筆畫…等等,但在輸出後的圖檔將不會帶有這些效果。



解決方法:透過點陣化圖層效果,即可輸出相對應的圖檔。
2. 無法輸出帶有遮色片效果的圖片



解決方法:將圖層轉為智慧型物件,即可輸出相對應的圖檔。
3. 無法依圖層混合模式輸出圖片






解決方法:無法解決
which are threatening his own sense of mortality.ドール アダルト3.
5 Common Myths About Workers Compensation Attorneys You Should Stay Clear Of workers’ compensation law
firms – Maxie,
and pleasurablDespite this,エロ ラブドールfor many masturbation remains guilt-ridden.
it’s impossible to tell whether people seek sex partners in an effort to “self-medicate”—in other words,エロ ラブドールto reduce the emotional pain they are experiencing by seeking sexual connections with others,
ダッチワイフ エロ” The traits were measured on a three-point scale with 0 indicating “does not apply at all,” 1 indicating “applies somewhat,
11 “Faux Pas” You’re Actually Able To Make With Your Fridgemaster Chest Freezer electronics lg refrigerator (glamorouslengths.com)
I’m afraid I would feel too much,オナホ 高級and I can’t bear it.
ラブドール 女性 用like an image or specific movement with my hands (uh, masturbation).
We stumbled over here different web page and thought I might as
well check things out. I like what I see so now i’m following you.
Look forward to exploring your web page for a second time.
20 Reasons To Believe Gatot Kaca Fury Demo Will Not Be Forgotten Demo Slot Gatot Kaca Rupiah
Центр сертификации https://www.rospromtest.ru осуществляет деятельность по содействию в подтверждении соответствия продукции и услуг требованиям нормативных документов, технических регламентов Таможенного союза, и сертификации ISO. Мы оказываем полный комплекс услуг в сфере сертификации.
The 10 Most Scariest Things About U Shape Settee u shape settee; Louella,
Nine Things That Your Parent Taught You About Keys Locked In Vehicle Keys Locked in vehicle
リアル ラブドールfamily obligations,household responsibilities,
How Auto Accident Settlement Became The Hottest Trend
In 2023 Auto Accident Lawsuits
The 10 Most Scariest Things About Upvc Repairs Near Me Upvc repairs near Me
Hey there! Quick question that’s totally off topic.
Do you know how to make your site mobile friendly?
My blog looks weird when browsing from my iphone. I’m
trying to find a theme or plugin that might be able to resolve this issue.
If you have any suggestions, please share.
Cheers!
Полезные советы по использованию промокодов. https://free-promocode.ru .
The 10 Scariest Things About Online Purchasing Websites In Uk online purchasing websites in uk (Mario)
as my colleague Marty Klein has noted, “Feeling out of control is different than being out of control.ラブドール sex
RuNet https://gallerix.asia ?????????????????? ??4?????,?????????????????
10 Myths Your Boss Has Concerning Private Psychiatrist Edinburgh private Psychiatrist consultation cost
ラブドール 高級involving the least emotionally intimate experience and often take place between strangers or after brief acquaintance.Booty calls refer to a communication initiated with the urgent intent of having a sexual encounter.
as noted in both the aforementioned research projects,there is not a lack of potential underlying causes of this condition.ラブドール
9 . What Your Parents Taught You About Hiring Truck Accident Attorney truck accident Attorney
The Indonesian Pharmacists Organization (Pafi) іs аctually
a specialist company devoted tߋwards accelerating pharmacy method аs
well as health care іn Indonesia witһ education and learning,
educating, neighborhood wellness plan advocacy, ɑs wesll as campaigns.
Pafi mаkes sure pharmacists аre actually geared ᥙp along with the
moѕt recent know-howtowards supply һigh tοp premium аnd
alѕο secure pharmacy solutions tοwards еveryone.
Ten Taboos About Costa Gift Set You Should Never Share On Twitter 221878.xyz
Все актуальные промокоды в одном месте. Все актуальные промокоды в одном месте. .
The Most Innovative Things Happening With Treehouse Bed treehouse bunk bed Uk (olderworkers.com.au)
Guide To White Sectional Sofa: The Intermediate Guide In White Sectional Sofa White sectional sofa