透過網頁讀取Photoshop PSD檔案內容

在專案中有需要透過網頁來讀取Photoshop PSD檔案的內部資訊,我們透過PSD.js備用載點)來實現這樣的功能,在官方提供的功能展示頁中,我們可以看到在頁面中只需引入psd.min.js後,加入透過少量的Javascript就可以針對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 here</p>
  </div>
  <div id="image"></div>
  <pre id="data"></pre>
  <script type="text/javascript">
  (function () {
    var 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) {
        var data = JSON.stringify(psd.tree().export(), undefined, 2);
        document.getElementById('data').innerHTML = data;
        document.getElementById('image').appendChild(psd.image.toPng());
      });
    }
  }());
  </script>
</body>
</html>

我們透過下圖這樣的一個PSD檔案對頁面進行測試,檔案中共有三個圖層,包含一個文字圖層。

頁面將PSD分析出結果後,以json格式顯示在頁面上,可以看到文字圖層的部分,不僅能讀到圖層名稱也包含文字內容和字型名稱。

{
  "children": [
    {
      "type": "layer",
      "visible": true,
      "opacity": 1,
      "blendingMode": "normal",
      "name": "Photoshop Text",
      "left": 302,
      "right": 723,
      "top": 90,
      "bottom": 128,
      "height": 38,
      "width": 421,
      "mask": {},
      "text": {
        "value": "THIS IS TEXT LAYER",
        "font": {
          "name": "MyriadPro-Regular\u0000",
          "sizes": [
            53
          ],
          "colors": [
            [
              0,
              0,
              0,
              255
            ]
          ],
          "alignment": [
            "center"
          ]
        },
        "left": 0,
        "top": 0,
        "right": 0,
        "bottom": 0,
        "transform": {
          "xx": 1,
          "xy": 0,
          "yx": 0,
          "yy": 1,
          "tx": 513,
          "ty": 127
        }
      },
      "image": {}
    },
    {
      "type": "layer",
      "visible": true,
      "opacity": 1,
      "blendingMode": "normal",
      "name": "PSD Icon",
      "left": 287,
      "right": 738,
      "top": 209,
      "bottom": 669,
      "height": 460,
      "width": 451,
      "mask": {},
      "image": {}
    },
    {
      "type": "layer",
      "visible": true,
      "opacity": 1,
      "blendingMode": "normal",
      "name": "Background",
      "left": 0,
      "right": 1024,
      "top": 0,
      "bottom": 800,
      "height": 800,
      "width": 1024,
      "mask": {},
      "image": {}
    }
  ],
  "document": {
    "width": 1024,
    "height": 800,
    "resources": {
      "layerComps": [],
      "guides": [],
      "slices": []
    }
  }
}

You may also like...

43,514 Responses

  1. EverettTuh表示:

    rate canadian pharmacies http://usacanadapharm.com/# USACanadaPharm
    canadian pharmacy near me

  2. EverettTuh表示:

    canadian pharmacy victoza https://usacanadapharm.com/# usa canada pharm
    buy prescription drugs from canada cheap

  3. Dwightkak表示:

    usa canada pharm: USACanadaPharm – the canadian pharmacy

  4. Albertbiave表示:

    http://usacanadapharm.com/# best canadian pharmacy online

  5. Albertbiave表示:

    https://usacanadapharm.com/# best canadian pharmacy

  6. Dwightkak表示:

    global pharmacy canada: northwest pharmacy canada – usa canada pharm

  7. Victoracara表示:

    Water and life
    Eth Mixer
    Lightning is a dramatic display of electrical power, but it is also sporadic and unpredictable. Even on a volatile Earth billions of years ago, lightning may have been too infrequent to produce amino acids in quantities sufficient for life — a fact that has cast doubt on such theories in the past, Zare said.

    Water spray, however, would have been more common than lightning. A more likely scenario is that mist-generated microlightning constantly zapped amino acids into existence from pools and puddles, where the molecules could accumulate and form more complex molecules, eventually leading to the evolution of life.

    “Microdischarges between obviously charged water microdroplets make all the organic molecules observed previously in the Miller-Urey experiment,” Zare said. “We propose that this is a new mechanism for the prebiotic synthesis of molecules that constitute the building blocks of life.”

    However, even with the new findings about microlightning, questions remain about life’s origins, he added. While some scientists support the notion of electrically charged beginnings for life’s earliest building blocks, an alternative abiogenesis hypothesis proposes that Earth’s first amino acids were cooked up around hydrothermal vents on the seafloor, produced by a combination of seawater, hydrogen-rich fluids and extreme pressure.
    Yet another hypothesis suggests that organic molecules didn’t originate on Earth at all. Rather, they formed in space and were carried here by comets or fragments of asteroids, a process known as panspermia.

    “We still don’t know the answer to this question,” Zare said. “But I think we’re closer to understanding something more about what could have happened.”

    Though the details of life’s origins on Earth may never be fully explained, “this study provides another avenue for the formation of molecules crucial to the origin of life,” Williams said. “Water is a ubiquitous aspect of our world, giving rise to the moniker ‘Blue Marble’ to describe the Earth from space. Perhaps the falling of water, the most crucial element that sustains us, also played a greater role in the origin of life on Earth than we previously recognized.”

  8. StephenCer表示:

    northwest canadian pharmacy: USACanadaPharm – canada discount pharmacy

  9. Albertbiave表示:

    https://usacanadapharm.com/# canadian pharmacy online reviews

  10. Poker Casino表示:

    Also visit my web page :: Poker Casino

  11. Dwightkak表示:

    USACanadaPharm: USACanadaPharm – canadapharmacyonline legit

  12. DonaldNadia表示:

    Water and life
    Eth Mixer
    Lightning is a dramatic display of electrical power, but it is also sporadic and unpredictable. Even on a volatile Earth billions of years ago, lightning may have been too infrequent to produce amino acids in quantities sufficient for life — a fact that has cast doubt on such theories in the past, Zare said.

    Water spray, however, would have been more common than lightning. A more likely scenario is that mist-generated microlightning constantly zapped amino acids into existence from pools and puddles, where the molecules could accumulate and form more complex molecules, eventually leading to the evolution of life.

    “Microdischarges between obviously charged water microdroplets make all the organic molecules observed previously in the Miller-Urey experiment,” Zare said. “We propose that this is a new mechanism for the prebiotic synthesis of molecules that constitute the building blocks of life.”

    However, even with the new findings about microlightning, questions remain about life’s origins, he added. While some scientists support the notion of electrically charged beginnings for life’s earliest building blocks, an alternative abiogenesis hypothesis proposes that Earth’s first amino acids were cooked up around hydrothermal vents on the seafloor, produced by a combination of seawater, hydrogen-rich fluids and extreme pressure.
    Yet another hypothesis suggests that organic molecules didn’t originate on Earth at all. Rather, they formed in space and were carried here by comets or fragments of asteroids, a process known as panspermia.

    “We still don’t know the answer to this question,” Zare said. “But I think we’re closer to understanding something more about what could have happened.”

    Though the details of life’s origins on Earth may never be fully explained, “this study provides another avenue for the formation of molecules crucial to the origin of life,” Williams said. “Water is a ubiquitous aspect of our world, giving rise to the moniker ‘Blue Marble’ to describe the Earth from space. Perhaps the falling of water, the most crucial element that sustains us, also played a greater role in the origin of life on Earth than we previously recognized.”

  13. TimothyDok表示:

    best canadian pharmacy online usa canada pharm canadian pharmacy prices

  14. TimothyDok表示:

    usa canada pharm USACanadaPharm my canadian pharmacy

  15. StephenCer表示:

    usa canada pharm: buying drugs from canada – usa canada pharm

  16. StephenCer表示:

    usa canada pharm: usa canada pharm – canadian drug pharmacy

  17. StephenCer表示:

    canadian mail order pharmacy: maple leaf pharmacy in canada – buy prescription drugs from canada cheap

  18. Albertbiave表示:

    http://usacanadapharm.com/# usa canada pharm

  19. Williamsnupt表示:

    nba轉播
    2025年NBA免費線上看直播:籃球投注與即時更新的完整指南

    隨著全球體育迷對線上博弈和賽事直播的需求不斷增長,NBA作為最受歡迎的籃球聯賽之一,自然成為了眾多球迷關注的焦點。2025年的NBA賽季將帶來更多精采的比賽,而如何免費觀看這些比賽並參與場中投注,已成為球迷們最關心的話題。本文將為您提供完整的NBA免費線上看直播教學、即時比分更新、以及相關的投注技巧。

    一、NBA免費線上看直播的管道
    不論是季後賽(4月-5月)還是總決賽(6月),NBA的每一場比賽都充滿激情與挑戰。以下是幾種常見的免費直播方式:

    1. 線上直播平台
    OB體育電視台 、鑫寶體育電視台 、SUPER體育電視台 等平台提供免費註冊服務,新用戶還可獲得168預測金,讓您在觀看比賽的同時也能進行運彩投注。
    只需簡單註冊帳號,選擇【熊貓體育】或【RG富遊體育電視台】,即可輕鬆進入NBA籃球LIVE直播。
    2. 電視轉播頻道
    華視NBA籃球頻道 、ELTA TV 、以及中華電信MOD 也提供64場全賽事的LIVE轉播,適合喜歡透過電視欣賞比賽的球迷。
    如果您偏好手機觀看,可以訂閱Hami Video NBA專區 ,每月僅需149元即可享受所有賽事的高清轉播。
    二、如何註冊/登入以免費觀看NBA直播?
    如果您想通過線上平台觀看NBA直播,以下是詳細步驟:

    點選【RG官網】或【富遊娛樂城】官網,選擇「註冊/登入」。
    輸入會員資料完成註冊。
    登入後,點選【熊貓體育】或【體育直播】分類。
    選擇NBA籃球視頻直播,即可免費觀看您感興趣的比賽。
    三、NBA即時比分與場中投注
    對於熱衷於運動彩券的球迷來說,NBA不僅是一場視覺盛宴,更是投注的好時機。以下是一些實用的投注建議:

    即時比分更新 :透過【RG富遊體育電視台】或【熊貓體育】,您可以隨時掌握比賽進展,並根據比分變化調整投注策略。
    場中投注技巧 :例如,在比賽關鍵時刻(如延長賽或最後三分鐘),利用即時數據進行快速下注,往往能提高勝率。
    此外,NBA季後賽和總決賽期間,各平台通常會推出特別優惠活動,例如加倍獎金或贈送預測金,讓您的投注更有趣味性。

    四、其他熱門賽事推薦
    除了NBA之外,2025年還有許多值得期待的體育盛事:

    2024夏季奧運 :涵蓋多項運動項目,是體育迷不容錯過的國際賽事。
    2024歐洲盃 :足球迷的年度盛宴,各國勁旅爭奪最高榮譽。
    2024 WBC世界棒球經典賽 :棒球愛好者的狂歡節,亞洲強隊表現備受矚目。
    2023-2024英超聯賽 :足球迷必追的頂級聯賽,精彩程度無與倫比。
    五、結語
    無論您是單純的NBA球迷,還是熱衷於運動彩券投注的玩家,2025年的NBA賽季都將為您帶來無限樂趣。透過本文介紹的免費直播管道與投注技巧,您可以輕鬆享受每場比賽的刺激與精彩。現在就趕快註冊帳號,加入這場籃球狂歡吧!

    立即行動!登入【熊貓體育】或【RG富遊體育電視台】,開啟您的NBA免費線上看之旅!

  20. CarlosBub表示:

    Water and life
    Eth Mixer
    Lightning is a dramatic display of electrical power, but it is also sporadic and unpredictable. Even on a volatile Earth billions of years ago, lightning may have been too infrequent to produce amino acids in quantities sufficient for life — a fact that has cast doubt on such theories in the past, Zare said.

    Water spray, however, would have been more common than lightning. A more likely scenario is that mist-generated microlightning constantly zapped amino acids into existence from pools and puddles, where the molecules could accumulate and form more complex molecules, eventually leading to the evolution of life.

    “Microdischarges between obviously charged water microdroplets make all the organic molecules observed previously in the Miller-Urey experiment,” Zare said. “We propose that this is a new mechanism for the prebiotic synthesis of molecules that constitute the building blocks of life.”

    However, even with the new findings about microlightning, questions remain about life’s origins, he added. While some scientists support the notion of electrically charged beginnings for life’s earliest building blocks, an alternative abiogenesis hypothesis proposes that Earth’s first amino acids were cooked up around hydrothermal vents on the seafloor, produced by a combination of seawater, hydrogen-rich fluids and extreme pressure.
    Yet another hypothesis suggests that organic molecules didn’t originate on Earth at all. Rather, they formed in space and were carried here by comets or fragments of asteroids, a process known as panspermia.

    “We still don’t know the answer to this question,” Zare said. “But I think we’re closer to understanding something more about what could have happened.”

    Though the details of life’s origins on Earth may never be fully explained, “this study provides another avenue for the formation of molecules crucial to the origin of life,” Williams said. “Water is a ubiquitous aspect of our world, giving rise to the moniker ‘Blue Marble’ to describe the Earth from space. Perhaps the falling of water, the most crucial element that sustains us, also played a greater role in the origin of life on Earth than we previously recognized.”

  21. StephenCer表示:

    USACanadaPharm: pharmacy rx world canada – buy drugs from canada

  22. DennisPam表示:

    best alarm clocks with radio cd playing clock radio

  23. Dwightkak表示:

    www canadianonlinepharmacy: canadian pharmacies that deliver to the us – USACanadaPharm

  24. AndreSpise表示:

    Кто-нибудь еще помнит Игросуп?
    https://vk.com/public229902184

  25. Albertbiave表示:

    http://usacanadapharm.com/# USACanadaPharm

  26. Albertbiave表示:

    https://usacanadapharm.com/# usa canada pharm

  27. Dwightkak表示:

    USACanadaPharm: usa canada pharm – usa canada pharm

  28. Albertbiave表示:

    http://usacanadapharm.com/# pet meds without vet prescription canada

發佈留言

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