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

12,557 Responses

  1. MichaelPlela表示:

    sildenafil sildenafil citrate 100mg for sale viagra pills

  2. hirirose表示:

    Only registered developers can ask/answer questions on the FluentU forums. Sign up today and become one of them!

    4 results

    The issue appeared with the latest version of Androirc (4.0.0, dated 12/09/2017). I think it’s a regression, as mentioned here ( https://cerafreuci.weebly.com

    6add127376 hirirose

  3. jaygal表示:

    It provides several built-in utilities for calculating various physicochemical properties such as and rate constants, activation energies, enthalpies, free energies, etc. Chemked-II features a comprehensive collection of structural and analytical databases. These make it an ideal repository for simulation studies involving mass spectrometry, cluster chemistry, reactions involving large numbers of species and quantum chemical calculations. Similar to many other applications in the PM6 field, it also gives complete access to other properties and chemistry-related features that https://biartictempccut.weebly.com

    6add127376 jaygal

  4. erbelli表示:

    Sound Forge Mobile Edition is the basic sound editing software application available for the mobile devices.
    Features:
    The mobile edition doesn’t have a huge list of features like that for the full version. But the best feature to use while on the go is the access to the database of sounds and assigning your device. The application is capable of creating MIDI and BPM based sound with a few taps.
    However, the only download available is the trial version, which requires you to completely http://www.51xiancheng.com/common/suda?from=wap&site_id=937&target_url=https://gluctacnaugran.weebly.com

    6add127376 erbelli

  5. elvkaik表示:

    Pepsin secretion from the gastric mucosa of a monogastric mammal in short-circuit current recordings.
    Secretion of pepsin from the gastric mucosa was studied by means of intragastric administration of 0.1 N NH4Cl from channels implanted in rat stomachs for 4 weeks. Concentration gradients between stomach lumen and intragastric solution with or without alpha-amylase activity were prevented by subtilisin and peps https://www.megaprosto.ru/bitrix/rk.php?goto=https://maredisu.weebly.com

    6add127376 elvkaik

  6. elvkaik表示:

    Pepsin secretion from the gastric mucosa of a monogastric mammal in short-circuit current recordings.
    Secretion of pepsin from the gastric mucosa was studied by means of intragastric administration of 0.1 N NH4Cl from channels implanted in rat stomachs for 4 weeks. Concentration gradients between stomach lumen and intragastric solution with or without alpha-amylase activity were prevented by subtilisin and peps https://www.megaprosto.ru/bitrix/rk.php?goto=https://maredisu.weebly.com

    6add127376 elvkaik

  7. jarflor表示:

    Apex will also feature an RPM and source RPM package for those who wish to maintain their own servers on their own environments. For those who are looking for a simple way to set up a secure web server, Users and System Administrators should give apex a try.

    A PHP based web page editor. Homepage at

    About Us

    Translate

    Social

    Secure

    Disclaimer – Privacy

    This site uses https://ludisdownty.weebly.com

    6add127376 jarflor

  8. ramfont表示:

    The chordman application have been created for total players but more geared for combo’s, vintajes and pickers.

    Chordman is based on a follow up on the Chordman Pro application. It is a free to use program that use the Pro application to design playable chord shapes and provide audio playback of the chords.

    Apart from playing the chords you can visually design them to make them playable and save them to your computer for your future. To get started use the https://lpenicepis.weebly.com

    6add127376 ramfont

  9. garfon表示:

    Not all features are available across providers, but they are certainly a good addition nonetheless.

    Downloading content from the Internet has never been more convenient. AnyStream is a handy application for browsers allowing you to download media content from Amazon and Netflix to your local PC; photos, music, movies and more. More about Anystream is on the developer’s site.
    Other information about Anystream 
    Release Date: 17.12.2015
    Category: Video & Audio
    Platforms http://maps.google.iq/url?sa=t&url=https://saddrirabpie.weebly.com

    6add127376 garfon

  10. gesywor表示:

    Cisco Video Cloud Viewer is a lightweight, plug-inless media player that you can install on any Windows system and enhances Microsoft Windows Media Center experience. It is capable of playing all standard media formats like MPEG-4, MPEG-2, WMV, RealMedia, MP3, AAC, WMA, etc.

    BoringDirect Toolbar is designed to enhance Internet browsing. It can be inserted as a toolbar to Microsoft Explorer (Internet Explorer) or Mozilla Firefox. https://meifealdaari.weebly.com

    6add127376 gesywor

  11. willodd表示:

    NEF\/M digiMatch is an automated compatible software (apps) for Adobe dgn, nef, mrp (contains all modifications) or pdf files, that converts them in another, more handy (or NEF) image formats like 0a1000, or 1600 or 2000 (if possible), whih allow to use the full panorama feature of your camera.

    NEFReID is a tool that help you to calculate the camera exposure time of a https://myslaverhi.weebly.com

    6add127376 willodd

  12. malgeo表示:

    Charivari Extemporánea

    The Charivari is a French traditional game which has been described as “the world’s oldest practical joke”. It is usually played with a string, like a whip, as a prop, and the person who has been whacked at is chosen to walk along a closed path which may be a tree, a wall or even a house. The route can be quite long, especially if the Charivari begins with a whip, also known as a sw https://madanecta.weebly.com

    6add127376 malgeo

  13. pazyhar表示:

    Checkpoints is an idea for study and for revision. The idea of the program is to store various pieces of information that the user can make available to check later. It also helps with the process of studying for different exams. The possible information that can be stored are: definitions of terms, solutions of exercises (if there are any) and mathematical methods.

    This is a 2.4 MB. In the zip file you will find the installation file. The file you must extract and https://riawristaptio.weebly.com

    6add127376 pazyhar

  14. uthmcae表示:

    You can easily change background image and color on demand with one single click.
    With a simple X1 click, you can delete firefox toolbars, uninstall blocks, and remove the unwanted menu items in Firefox. About this program: for more information.
    * Disclaimer:
    ¡ÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄ� https://boffosare.weebly.com

    6add127376 uthmcae

  15. savengl表示:

    If you choose to make changes to WD SmartWare settings, click Back to change the settings.
    WARNING: Before making changes to configuration settings, you will loose any data or configuration which was stored on your computer during the update.
    In Chapter 6, “Quick Start Guide” Click the More Options button to access the content information section.
    In the Content Information page, click the Managing Backup Information to access this specific section.
    You must select an existing local backup directory or browse to manually create https://kilzicoopo.weebly.com

    6add127376 savengl

  16. hendrenn表示:

    T@B Icon Ripper has been well tuned for speed (in terms of file transfer speed), memory usage and image quality. The command line tool has been thoroughly tested over a wide range of devices. It can be safely used without any problems.
    It can process 2.5 GiB of image files per directory.

    The tool offers a set of command line switches to control certain aspects of the process.
    For example:
    [supported https://grenmetzturo.weebly.com

    6add127376 hendrenn

  17. Dschmv表示:

    ceftin drug – order methocarbamol online cheap cheap tadalafil tablets

  18. MichaelPlela表示:

    viagra pills viagra pills sildenafil 100 mg lowest price

發佈留言

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