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

35,294 Responses

  1. Diplomi_phpi表示:

    купить диплом медицинский в казани 4russkiy365-diplomy.ru .

  2. Barrybib表示:

    Generic Viagra for sale: Fast Pills For Men – generic sildenafil

  3. Donaldabula表示:

    cheapest cialis MaxPillsForMen.com Cialis without a doctor prescription

  4. Diplomi_brpi表示:

    купить диплом оригинал купить диплом оригинал .

  5. сравнение производительности процессоров http://www.topcpu.ru/ .

  6. какой процессор лучше [url=http://topcpu.ru]http://topcpu.ru[/url] .

  7. Donaldabula表示:

    buy Viagra online Viagra generic over the counter buy Viagra over the counter

  8. Diplomi_mqpi表示:

    купить диплом в бугульме 4russkiy365-diplomy.ru .

  9. Jameshic表示:

    Ethena Fi – Your platform for decentralized financial services
    ethena
    Invest, exchange, and manage your assets with confidence on Ethena Fi
    Discover the power of decentralized finance with Ethena Fi. As the world moves towards decentralized financial solutions, Ethena Fi offers you a platform to explore the limitless possibilities of cryptocurrency investments, exchanges, and asset management.

    At Ethena Fi, we believe in empowering individuals to take control of their financial future. Whether you’re an experienced investor or new to the world of cryptocurrencies, our user-friendly platform provides you with the tools and resources you need to succeed.

    With Ethena Fi, you can:

    Invest in a wide range of cryptocurrencies, including Bitcoin, Ethereum, and more
    Exchange digital assets quickly and securely
    Manage your portfolio with ease
    Access innovative financial products and services
    Join thousands of users who have already started their journey to financial freedom with Ethena Fi. Sign up today and experience the future of decentralized finance!

  10. рейтинг игровых процессоров topcpu.ru .

  11. сравнение производительности процессоров https://topcpu.ru .

  12. сравнение процессоров amd topcpu.ru .

  13. Robertjep表示:

    Explore Blockchain Networks with Chainlist
    In the ever-evolving realm of blockchain technology, finding and connecting to the right network can be daunting. Chainlist is here to simplify that process, offering users a comprehensive directory of various blockchain networks.
    chainlist crypto
    What is Chainlist?
    Chainlist is a user-friendly platform designed to help you connect easily to different blockchain networks. It ensures you can access the required network settings, thereby facilitating the process of connecting your wallet to these networks reliably.

    Features of Chainlist
    Comprehensive Listings: Access an extensive list of blockchain networks.
    Easy Connection: Connect to networks directly through your wallet interface with just a few clicks.
    Up-to-date Information: Keep up with the latest network updates and technical details.
    Why Use Chainlist?
    Chainlist offers a seamless experience for users who need to navigate the myriad of blockchain networks available today. Whether you are a developer, a crypto enthusiast, or someone new to the crypto space, Chainlist provides:

    Accessibility: Simplifies accessing various networks without needing deep technical knowledge.
    Efficiency: Save time by using Chainlist’s straightforward interface to find and connect to networks.
    Reliability: Depend on updated settings to ensure smooth transitions between networks.
    How to Use Chainlist
    Using Chainlist is intuitive. Here’s a simple guide to get started:

    Visit the Chainlist website.
    Browse through the list of available networks.
    Find your preferred network and click ‘Add to Wallet’.
    Follow any additional prompts to complete the connection.
    Once you’re connected, you can start exploring the decentralized applications (dApps) and services that the blockchain network offers.

    Conclusion
    With Chainlist, accessing the blockchain world is no longer overwhelming. Its user-centric platform reduces complexity, making it an invaluable tool for anyone looking to explore or develop on different blockchain platforms. From seamless wallet integration to accurate network data, Chainlist paves the way for blockchain accessibility and innovation.

    Check out today and start your journey into the decentralized future.

  14. рейтинги процессоров для пк http://www.topcpu.ru .

  15. сравнение процессоров intel [url=https://topcpu.ru/]https://topcpu.ru/[/url] .

  16. Charlesbot表示:

    http://fastpillsformen.com/# buy Viagra online

  17. Mathewnus表示:

    Introducing the Zircuit Token System
    The Zircuit token, a pivotal element in the blockchain landscape, plays a crucial role in enabling efficient transactions and offering enhanced security. Designed for seamless integration into various platforms, it aims to revolutionize the way digital currencies are perceived and utilized.
    [url=https://web-zircuit.com]zircuit[/url]
    Key Advantages of the Zircuit Token
    Enhanced Security: Security is a core benefit of utilizing the Zircuit token. By employing advanced cryptographic techniques, it ensures that transactions are secure, safeguarding user data and funds from potential threats.
    Scalable Transactions: Zircuit token is engineered for scalability, allowing for a large number of transactions per second. This capability promises efficiency even as user numbers grow, ensuring smooth operations across digital platforms.
    Low Transaction Fees: One of the significant advantages of using the Zircuit token is the cost-effectiveness of its transactions. It boasts lower fees compared to traditional financial systems, making it an attractive option for users.
    Implementing Zircuit Tokens in Everyday Use
    The implementation of Zircuit tokens into daily transactions is designed to be straightforward. Users can manage their tokens seamlessly through dedicated wallets that offer user-friendly interfaces and robust security. Thanks to its decentralized nature, it enables trustless interactions, where intermediaries are reduced, thereby minimizing costs and enhancing speed.

    Furthermore, Zircuit tokens offer compatibility with various platforms, allowing users to transact with ease across a plethora of services. This flexibility is crucial for both individuals and businesses looking to integrate blockchain technology into their operations.

    In conclusion, the Zircuit token stands as a testament to the evolving nature of digital currencies, offering a secure, scalable, and cost-effective solution for modern financial transactions. As adoption continues to grow, the robustness of the Zircuit token system is likely to play a critical role in shaping the future of digital exchanges.

  18. Donaldabula表示:

    Cialis 20mg price in USA buy cialis online buy cialis pill

  19. EarnestAvada表示:

    Hi colleagues, pleasant article and good urging commented here, I am genuinely enjoying by these.

    https://ameli-studio.com.ua/headlight-sealing-after-accident.html

  20. Danielglync表示:

    Welcome to Vertex Protocol: Revolutionizing DeFi Trading
    Discover the revolutionary Vertex Protocol, your gateway to the world of decentralized finance (DeFi) trading. As the crypto landscape rapidly evolves, Vertex Protocol stands at the forefront, providing users with unparalleled seamless trading experiences and enhanced liquidity access.
    vertex protocol staking
    What Makes Vertex Protocol Stand Out?
    Vertex Protocol is more than just a trading platform. It is a designed to empower you with:

    Intuitive User Interface: Navigate the complex world of crypto with ease and efficiency.
    Advanced Security: Enjoy peace of mind with industry-leading security protocols and safeguarding of your assets.
    High Liquidity: Access deep liquidity pools to execute large trades with minimal slippage.
    Diverse Asset Options: Explore a wide array of cryptocurrencies and tokens.
    Unlock Potential with Vertex’s Features
    Leverage the full potential of Vertex Protocol with these standout features:

    Decentralized: Trustless and Secure
    Trading on Vertex ensures transparency and autonomy, free from third-party control, making it a trustless and secure choice for crypto enthusiasts.

    Efficient Trading Engine
    Benefit from fast, efficient trade execution supported by state-of-the-art technology that maximizes your trading efficiency.

    Community Governance
    Be a part of a community-driven , allowing you to have a say in the protocol’s future developments.

    Getting Started with Vertex Protocol
    Embarking on your DeFi journey with Vertex is straightforward. To get started:

    Sign up and create your account.
    Securely connect your wallet.
    Begin trading and explore diverse assets and liquidity options.
    Whether you are a seasoned trader or new to the crypto scene, Vertex Protocol offers the tools and resources you need to succeed.

    Join the Vertex Community
    Participate in webinars, discussions, and forums to stay informed and connected. The vibrant awaits, offering support and insights to enhance your trading journey.

    In conclusion, Vertex Protocol is your ideal partner in navigating the dynamic world of decentralized finance. Start today and experience the future of trading.

  21. сравнение процессоров для пк https://www.topcpu.ru .

  22. JustinBaide表示:

    Wygrywaj z 21 w blackjacku, twórz zwycięskie układy w pokerze, stawiaj zakłady w kasynie na żywo i baw się przy najlepszych grach online w kasynie na żywo. Dzięki zespołowi Grakasynonazywo.pl możesz teraz uzyskać dostęp do najpopularniejszych gier online w kasynie na żywo z urządzeń mobilnych i komputerów stacjonarnych, wybierając dla siebie najlepsze kasyno online w Polsce. https://grakasynonazywo.pl/

發佈留言

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