透過網頁讀取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...

47,066 Responses

  1. えろ 人形表示:

    The first time I had sex was when I ロボット セックスwas 15 and my boyfriend at the time was 16. The day before was Valentine’s Day and he had taken me out.

  2. エロ 人形表示:

    says the husband, poking her in the crotch of her jean shorts with えろ 人形one finger. She bops him on the shoulder but laughs.

  3. えろ 人形表示:

    Not everyone learns about the menstrual cycle,jydoll so making sure your partner understands it is the first thing to help normalize it. After they have that understanding, express that period sex is normal and has a lot of benefits.”

  4. 9 Things Your Parents Teach You About Upvc Windows Near
    Me upvc windows near me

  5. Does your website have a contact page? I’m having problems locating it
    but, I’d like to send you an email. I’ve got some creative ideas for your blog you might be interested in hearing.
    Either way, great blog and I look forward to seeing it improve
    over time.

  6. 人形 エロ表示:

    Once it was in, he tried to thrust in and out,オナドール but that was probably not the smartest thing for him to do since it burned really bad. It did so for a bit, but kind of went away. And when his penis finally went in, I thought I bled, but I didn’t.

  7. エロ 人形表示:

    There’s a lot that can be done just in terms of exploring externally,jydoll Dr. Olson says, by way of offering a mutually beneficial potential outcome.

  8. 人形 エロ表示:

    If nothing else, you get some laughs together—but really, ラブドール avgames are a great way to learn new things about each other and

  9. 人形 エロ表示:

    It’s happened to me before; like when I matriculated at a women’s college and えろ 人形found myself surrounded by 1,500 ambitious Hermione Granger–types, or when I find out the person I’m talking to is also from New Jersey.

  10. エロ 人形表示:

    we still have a long way to go. And in my experience, えろ 人形one of the last frontiers in sexual wellness is period sex.

  11. えろ 人形表示:

    Certified sex coach Gigi Engle says, “jydollThe most important thing is to be direct,

  12. エロ 人形表示:

    but also to prepare himself for penetrating the ass)オナドール and that feeling from going from dirty ass eating and wetness to the tip slowly penetrating is just so fucking wild.”

  13. えろ 人形表示:

    This allows our bodies to have different response signals ラブドール sexto varying speeds, motions, and intensities.

  14. 人形 エロ表示:

    Ahead, we’ve spoken to sex experts and ラブドール aveducators about the importance of sex games,

  15. Yeah, ask me how that went? Hehehe. He opened his eyes and helped me remove his briefsセックス ロボット and then he helped me lay down on my air mattress, lifted my legs up.

  16. and the sensations they can offer range from gentle ラブドール sexto mind-blowingly intense.

  17. Getting ready for this date resembles how I get ready for others: ラブドール オナニーshower and blast Beyoncé and text my friends about what could go right and wrong.

  18. えろ 人形表示:

    Others around you might say that they’re having sex all the timeロボット セックス but they could be exaggerating. It’s understandable, really – peer pressure can be a difficult thing to deal with, especially when you’re new to sex and relationships.

  19. エロ 人形表示:

    Then also, the fluttering contractions of the pelvic floor muscles canえろ 人形 help provide relief to some of those cramps in some women.

  20. 人形 エロ表示:

    But the couple announces they are going back to their room to fuck. It’s casual,ラブドール オナニー like someone begging off because they’re tired. I wish them well and,

  21. an openness, an honesty, a lightness of being.えろ 人形 They are quite literally lightened—via the absence of clothing’s weight—but also without the weight of propriety

  22. えろ 人形表示:

    ‘I’m meant to wank with this? It looks like a coffee cup!’ We’re staring, ラブドール 女性 用brows furrowed, at what looks like a reusable thermos.

  23. えろ 人形表示:

    I’d like to repeat the act but only if it’s a CNC [consensual non-consent] type scenario. オナドールThen I can pretend I don’t like it even though I obviously am turned on by how turned on he gets.

  24. えろ 人形表示:

    Needless to say he didn’t last long after a sensory overload.” オナドール“Giving head after anal. I honestly didn’t even realise what I was doing

  25. 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.

  26. えろ 人形表示:

    ‘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

  27. 人形 エロ表示:

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

  28. You’ll Be Unable To Guess Upvc Window Repair Near Me’s Secrets upvc window repair near me (http://kilian.co.kr/)

  29. porno_kxEi表示:

    смотреть русское порно анал смотреть русское порно анал .

  30. The 10 Most Terrifying Things About Dangerous Drugs Attorneys dangerous Drugs attorneys

發佈留言

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