透過網頁讀取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,998 Responses

  1. 19 of those who identify as bisexual say all or most of the important people女性 用 ラブドール in their lives are aware of their sexual orientation. In contrast, 75 of gay and lesbian adults say the same.

  2. エロ 人形表示:

    All of the therapists I spoke to said they frequently spoke to men who were straight-identifying and felt 女性 用 ラブドールafraid to explore their sexual attraction to the same sex, so kept their feelings hidden.

  3. many people experience a higher libido or sense of horniness.” jydollOvulation takes place about 14 days before the start of one’s period, and is the process during which mature eggs are released from the ovaries.

  4. えろ 人形表示:

    I even decided to refrain from kissing the man who’d become ラブドール avmy husband until our wedding day.

  5. No one has a right to your body,ロボット セックス just like you don’t have any rights to anyone else’s body. If you don’t want to take part in sexual activities, it’s your right to say no. Sexual consent is a must-have, every time you have sex.

  6. When it comes to your first time, many people wonder,ロボット セックス and sometimes worry about, being able to orgasm (coming or climaxing) and making their partner orgasm.

  7. エロ 人形表示:

    The first guy who initiated it, when I was only 14, almost succeeded, オナドールbut I kept on remembering my values and the principles I had set for myself.

  8. A bemused “sure” falls out of my drowsy, sunburned face.ラブドール オナニー What the hell have I just done?, I wonder as he saunters away.

  9. Hi there! This is my first comment here so I just wanted to give a
    quick shout out and tell you I truly enjoy reading through your blog posts.
    Can you recommend any other blogs/websites/forums that go over
    the same subjects? Appreciate it!

  10. 人形 エロ表示:

    still holds a strong influence over how individuals feel they can express女性 用 ラブドール themselves.

  11. エロ 人形表示:

    And when I asked men to anonymously share some reasons why they’d turn down sex,ラブドール 女性 用 the most common reasons cited were body image related, being tired or stressed with work.

  12. えろ 人形表示:

    Plus, as with most relationship woes, jydollperiod sex is not a zero-sum game!

  13. Another major concern that women have about period sex is ラブドール sexthat the smell of their period will upset their partner. To that idea, Dr. Olson counters,

  14. Engle adds that if that’s the case, but period sex jydollis important to you, it’s important to express that sentiment to your partner.

  15. エロ 人形表示:

    My dinner companions fly home the next morning, which is kind of a relief. ラブドール オナニーWere we going to be buddies at the buffet every day? I wake up feeling like the college party girl I never quite was

  16. えろ 人形表示:

    Like a wuss, I start the vacation proper by reading inラブドール オナニー a hammock on the prude side.

  17. It started one random night when we were in bed after a shower.オナドール I commanded her to get on her knees face down, ass up ,and I started going down on her from behind.

  18. sugar dating表示:

    This is the right site for everyone who hopes to find out
    about this topic. You know so much its almost hard to argue
    with you (not that I personally would want to…HaHa).
    You certainly put a fresh spin on a subject that’s been written about for
    a long time. Great stuff, just wonderful!

  19. エロ 人形表示:

    My flow is heavy today,” or, “I’m having cramps, ラブドール sexso I’d like to go slow.”). This transparency will not only give your partner crucial insight

  20. えろ 人形表示:

    The next moment I felt his penis in line with my vagina, I slipped it in. オナドールThat was probably one of the most painful things I’ve experienced, but it wasn’t the worst compared to the second time.

  21. The materials and shape of the vibrator are often the mostラブドール av influential factors in how vibrators impact everyone differently,”

  22. For a couple of years, we explored in the privacy of our bedroom, 女性 用 ラブドールtaking turns restraining each other and mixing pain and pleasure. And then

  23. 人形 エロ表示:

    I could just see in his face it was such an amazing ロボット セックスfeeling for him to be in me and he moaned/sighed when he came.

  24. 人形 エロ表示:

    He started jacking me off and asked me to jack him off. I was surprised but not complaining.セックス ロボット I was about to cum, he told me to cum on him, I got up on my knees, leaned forward and came all over his stomach.

  25. エロ 人形表示:

    they found that – partly down to the fact that bisexual men have, as part of trying to understand their sexuality, 女性 用 ラブドールquestioned the negative aspects of masculine character traits – they were better lovers and fathers.

  26. えろ 人形表示:

    He was totally wrong for me anyway, definitely not the kind of manオナドール I wanted to give that special part of myself to. Since then, my mind never wavered regarding the matter.

  27. えろ 人形表示:

    Once you know what materials you’re selecting and the type of stimulation you’re going for,ラブドール av Fretz recommends staying open-minded. After all, the world of sex toys is characterized by constant innovation.

  28. Communicate with your partner and セックス ロボットget consent if you’re not sure. Find out more about sexual consent.

  29. えろ 人形表示:

    They were punished if they cried or yelled at [for showing emotion],ラブドール 女性 用 and most men don’t get the opportunity to work through that. It’s not to excuse behaviour, it’s just to deepen the story. Misogyny, sexism and the patriarchy impacts everyone.’

  30. 人形 エロ表示:

    Sex can only be good when you’re both clear-headed and equally excited about it. ロボット セックスThat also means if your partner’s drunk or passed out, you can’t get consent from them.

發佈留言

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