透過網頁讀取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. 無法依圖層混合模式輸出圖片






解決方法:無法解決
Для эффективного продвижения вверх по карьерной лестнице нужно наличие официального диплома ВУЗа. Быстро приобрести диплом об образовании у проверенной фирмы: damdiplomisa.com/kupit-v-spb-diplom-5/
1win moldova download http://www.1win5026.ru .
canadian drugs pharmacy: canadian pharmacy no scripts – USACanadaPharm
طرح جامع پویش دانشگاه آزاد، دانشگاه آزاد اسلامی در راستای ایفای نقش محوری خود در تربیت نیروی انسانی متخصص و کارآمد برای کشور،
اقدام به راه اندازی طرح جامع پویش دانشگاه آزاد
نموده است.
Aged 15, New Zealander Sam Ruthe has already run a four-minute mile. He would ‘love to try and qualify’ for the 2028 Olympics
paraswap
Sam Ruthe had the eyes of thousands on him when he stepped onto a running track in Auckland just over a week ago.
Undaunted by the occasion, Ruthe went on to become the first 15-year-old to run a sub-four-minute mile, even managing a nonchalant shrug of the shoulders as he crossed the finish line.
The race was almost entirely engineered for the high school student to break the fabled four-minute barrier – a feat first achieved by Roger Bannister more than 70 years ago – but the weight of running history was a burden that Ruthe seemed to bear lightly.
The first three laps, he later said in a video documenting the race, “felt pretty comfortable – nothing too crazy.”
Perhaps the most intimidating part of his achievement occurred when Ruthe returned to school the next day, only to be immediately called into the principal’s office.
“He’s like, ‘Alright, so you’re gonna have to go up on stage and we’ll get the whole school to clap you,’” Ruthe tells CNN Sports’ Patrick Snell. “It was really scary, actually. I headed into class and everyone thought I was famous.”
It’s easy to forget, given his history-making performance last week, that Ruthe is like most other 15-year-olds in New Zealand. He goes to school, spends time with his friends, and helps with chores around the house.
He also just happens to be one of the most exciting middle-distance runners on the planet, one of the latest star athletes to emerge from sports-mad New Zealand.
usa canada pharm: canadian pharmacy world – canadadrugpharmacy com
1wi. 1wi. .
darknet site onion dark website
mostbet официальный сайт mostbet7002.ru .
драгон мани официальный сайт играть http://dragon-money30.com .
tor drug market darknet market
казино онлайн kg mostbet5004.ru .
Bookmarking this for later.
dark markets 2025 dark web drug marketplace
What’s up, after reading this remarkable paragraph i am too delighted to share my experience here with friends.
купить диплом задним числом купить диплом задним числом .
1win login nigeria https://1win18.com.ng .
UsaIndiaPharm: п»їlegitimate online pharmacies india – UsaIndiaPharm
UsaIndiaPharm: USA India Pharm – UsaIndiaPharm
Tyler O’Neill hits record-extending sixth straight Opening Day home run
orbiter finance
For six seasons in a row, Tyler O’Neill has homered on MLB Opening Day.
Making his debut for the Baltimore Orioles on Thursday, O’Neill started the season with his record-extending sixth straight home run on Opening Day during his team’s 12-2 win against the Toronto Blue Jays.
No other player has homered on more than four consecutive Opening Days, with the 29-year-old outfielder’s three-run shot sending the Orioles into a 5-0 lead at the top of the third at Rogers Centre.
Todd Hundley (1994-97), Gary Carter (1977-80) and Yogi Berra (1955-58) all hit four consecutive home runs on Opening Day, while the Major League Baseball record for the total number of Opening Day home runs is held jointly by Adam Dunn, Ken Griffey Jr. and Frank Robinson on eight.
“I’m just not trying to make too much of it,” O’Neill told reporters about his streak. “I’m just trying to go out, have a good first at-bat and see what the game gives me from there.
“Obviously, I understand what’s going on, but it’s not like I’m going out there trying to do anything crazy.”
O’Neill, who signed a three-year, $49.5 million contract to join Baltimore from the Boston Red Sox in the offseason, finished three-for-three with three RBIs and two walks against the Blue Jays.
“It’s a little different when the lights turn on and you’ve got to show up, so it was really cool to see all the guys show up today,” he said. “We got after it out there.”
While the first two games of the MLB regular season took place between the Chicago Cubs and Los Angeles Dodgers in Tokyo last week, Thursday marked the first official day of the season in the United States.
mostbet kg http://www.mostbet5006.ru .
top 10 online pharmacy in india: top online pharmacy india – india pharmacy
USA India Pharm: UsaIndiaPharm – п»їlegitimate online pharmacies india
Купить диплом любого университета!
Мы готовы предложить документы институтов, которые находятся на территории всей РФ.
diplomt-v-chelyabinske.ru/kupit-diplom-zanesennij-reestr-2/
best online pharmacy india: buy medicines online in india – indian pharmacy
indianpharmacy com: indian pharmacy – USA India Pharm
Для эффективного продвижения вверх по карьере необходимо наличие диплома университета. Быстро и просто заказать диплом о высшем образовании у сильной компании: fastdiploms.com/gde-kupit-diplom-12/
Заказать диплом ВУЗа!
Мы можем предложить документы ВУЗов, которые находятся на территории всей РФ.
diplomh-40.ru/kupit-diplom-s-reestrom-tsena-2/
darkmarket url darknet drugs
USA India Pharm: UsaIndiaPharm – cheapest online pharmacy india