透過網頁讀取PSD後,依圖層輸出PNG檔案

在前面介紹過網頁可以讀取PSD檔案並擷取到該檔案的資訊,接著我們會希望能透過網頁上傳PSD檔之後,依照圖層來輸出圖片,同樣是利用PSD.js來輔助進行,可以透過我們製作的範例頁面來進行輸出測試。

預設輸出效果


透過PSD.js可將PSD內的各圖層輸出成PNG圖檔,亦可轉成Base 64圖檔格式,惟輸出時每個圖檔的尺寸並不會根據整體PSD檔大小來配置。

圖層配置

Layer 1 (421 x 38)
Layer 2 (490 x 479)
Layer 3 (1024 x 800)

<!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中並不具備這樣的功能,於是我們透過下述的方式來達成:

  1. 擷取PSD資訊並將圖檔轉為Base 64格式
  2. 產生與PSD尺寸大小相同的HTML Canvas
  3. 將產生的Base 64圖檔,依照原始位置放入Canvas中
  4. 將Canvas轉成PNG圖檔
圖層配置
Layer 1 (1024 x 800)
Layer 2 (1024 x 800)
Layer 3 (1024 x 800)

可以參考我們製作的範例頁面

<!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. 無法輸出帶有遮色片效果的圖片

圖層設定
Before
After

解決方法:將圖層轉為智慧型物件,即可輸出相對應的圖檔。

3. 無法依圖層混合模式輸出圖片

Layer 1
Layer 2
Layer 3
Layer 4

解決方法:無法解決

You may also like...

46,882 Responses

  1. えろ 人形表示:

    My deck also offers a private hot tub, and I’m sitting in the ラブドール オナニーbubbling water alone watching the sunset with a champagne flute when a muscular man and his penis walk by.

  2. 人形 エロ表示:

    Stewart agrees, referencing three primary benefits for couples engaging in sex games:ラブドール av “They help you to spend quality time together and get to know each other in a different way;

  3. May I simply say what a comfort to uncover a person that genuinely understands what they are discussing
    on the web. You certainly know how to bring a problem to light and make it important.
    A lot more people have to look at this and understand this side of the story.
    I can’t believe you’re not more popular since
    you most certainly have the gift.

  4. えろ 人形表示:

    ‘We wanted to look at sexual pleasure as a whole,’ CEO Koichi Matsumoto says, through a translator. ‘ラブドール 女性 用Our vision was to make sexuality and sexual health something that is richer, fuller

  5. えろ 人形表示:

    Then I ‘made’ her go down on me. The sex was really hot. オナドールNow when we have sex it’s usually some type of CNC. It’s fun. Remember to be safe and use a safe word.”

  6. えろ 人形表示:

    She the most beautiful and Sweet Girl I ever meet she the one whoセックス ロボット I want protect and love for the whole years I will make sure to protect her and make her mine Even if it betraying my Kingdom I will do it for her

  7. 人形 エロ表示:

    Even without orgasm, I’ve enjoyed all my sexual encounters. セックス ロボットThat first-time is still some of the best sex I’ve ever had.

  8. Sexual pleasure is an incredibly personal, ラブドール avsubjective experience, so selecting the right vibrator should be one, too.

  9. エロ 人形表示:

    She found, largely, that they did. ‘I found that men want to feel ラブドール 女性 用desired and receive romantic gestures, rather than always being the one to initiate those things,’ she says.

  10. I wanted to lose my virginity, セックス ロボットbut I didn’t want my first time to be with someone I was in a relationship with. I’d heard stories from people who gave their virginity to their boyfriends and had their hearts broken.

  11. 人形 エロ表示:

    explore new territory free from the inhibitions that might have ラブドール avprevented you from asking them to ‘go there’ or ‘do that.'”

  12. So if you’re unsure about whether or not you’d like sexual jydollstimulation during menstruation

  13. Stewart agrees, referencing three primary benefits for couples engaging in sex games:ラブドール av “They help you to spend quality time together and get to know each other in a different way;

  14. えろ 人形表示:

    The reality? ‘It just didn’t happen,’ she says. ‘We spoke and I realised that I have a much ラブドール 女性 用stronger desire for sex than my partner does… but that was hard for me to accept.

  15. The No. 1 Question Everyone Working In Upvc Patio Doors Should Be Able To Answer Upvc Door near Me

  16. 人形 エロ表示:

    This situation can make you feel like the odd one out, especially if you’re young and still figuring out your own sexual desires but it’s important to know that there is no deadline for having sex!

  17. Before I entered the world of college, I was one of those individuals オナドールstrongly against sex before marriage. In my mind set, abstinence was always the way to go, and the idea of sex made me feel immature and uncomfortable.

  18. 人形 エロ表示:

    we were so tired I don’t remember if we both came again or not. セックス ロボットIt was so fucking hot, we were afraid nearby campers heard us.

  19. I am not ready to go all the way. As much as I feel I can’t wait for marriage,オナドール I also feel it would be worth the wait. I have told him of my concerns

  20. エロ 人形表示:

    And if your partner still refuses to have period sex? jydoll“There will be some people who aren’t aroused by period sex in any way,” she admits,

  21. 人形 エロ表示:

    Sex, oral, anal, sex toysロボット セックス masturbation – there’s a big wide world of sex out there for you to navigate.

  22. [They think] they should be a sexual machine and just want to fuck people.ラブドール 女性 用[Stereotypes] reduce sex down to a functionality.’ Similarly,

  23. I discovered pony play seven years ago, at one of my very first BDSM events—女性 用 ラブドールa private play party at a community member’s home.

  24. Some people with vaginas experience an increase or decrease in libido while they’re menstruating, えろ 人形while others find that their sex drives remain more or less the same.

  25. えろ 人形表示:

    I can’t remember exactly what made セックス ロボットme stop, but I was in a good mood that day.

  26. Foreplay also means that when you do get to it, ロボット セックスthe mechanics of sex are easier and less likely to be painful. We’d suggest having some water-based lube handy, especially for anal sex.

  27. エロ 人形表示:

    I gave my boyfriend a rim job while we were 69ing. I just went for it and damn!オナドール I never thought I’d be into that but he was always curious and wanted it from me so I gave it a go. Now I’m even more curious to play with his butt.”

  28. えろ 人形表示:

    struck with the guilt of having to face the rich セックス ロボットhandsome fiancée of her friend, she tries hard to stay away from him

  29. えろ 人形表示:

    Now I have met a wonderful guy, we first set eyes on each other 2 years ago.オナドール He is sweet, caring and really loves me. However, the issue of sex has come up again.

  30. エロ 人形表示:

    Croydon. I asked inappropriate questions at parties, sat in shopsラブドール 女性 用 surrounded by walls of dildos and I pestered friends,

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。