[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-7875":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":15,"stars7d":15,"stars30d":16,"stars90d":15,"forks30d":15,"starsTrendScore":15,"compositeScore":17,"rankGlobal":9,"rankLanguage":9,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":21,"hasPages":19,"topics":22,"createdAt":9,"pushedAt":9,"updatedAt":30,"readmeContent":31,"aiSummary":32,"trendingCount":15,"starSnapshotCount":15,"syncStatus":33,"lastSyncTime":34,"discoverSource":35},7875,"psd.rb","layervault\u002Fpsd.rb","layervault","Parse Photoshop files in Ruby with ease",null,"Ruby",3114,199,88,22,0,1,59,"MIT License",false,"master",true,[23,24,25,26,27,28,29],"document","file-format","parser","photoshop","psd","renderer","ruby","2026-06-12 04:00:36","# PSD.rb\n\n[![Travis CI](https:\u002F\u002Ftravis-ci.org\u002Flayervault\u002Fpsd.rb.png?branch=master)](https:\u002F\u002Ftravis-ci.org\u002Flayervault\u002Fpsd.rb)\n\nA general purpose Photoshop file parser written in Ruby. It allows you to work with a Photoshop document in a manageable tree structure and find out important data such as:\n\n* Document structure\n* Document size\n* Layer\u002Ffolder size + positioning\n* Layer\u002Ffolder names\n* Layer\u002Ffolder visibility and opacity\n* Font data (via [psd-enginedata](https:\u002F\u002Fgithub.com\u002Flayervault\u002Fpsd-enginedata))\n  * Text area contents\n  * Font names, sizes, and colors\n* Color mode and bit-depth\n* Vector mask data\n* Flattened image data\n* Layer comps\n\nPSD.rb is tested against:\n\n* MRI 1.9.3, 2.0.0, 2.1.0\n* JRuby (1.9.3 mode)\n\nIf you use MRI Ruby and are interested in significantly speeding up PSD.rb with native code, check out [psd_native](https:\u002F\u002Fgithub.com\u002Flayervault\u002Fpsd_native).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n    gem 'psd'\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install psd\n\n## Usage\n\nThe [full source code documentation](http:\u002F\u002Frubydoc.info\u002Fgems\u002Fpsd\u002Fframes) is available, but here are some common ways to use and access the PSD data:\n\n### Loading a PSD\n\n``` ruby\nrequire 'psd'\n\npsd = PSD.new('\u002Fpath\u002Fto\u002Ffile.psd')\npsd.parse!\n```\n\nOr, if you prefer the File.open way of doing things, you can do that too.\n\n``` ruby\nrequire 'psd'\n\nPSD.open('path\u002Fto\u002Ffile.psd') do |psd|\n  p psd.tree.to_hash\nend\n```\n\nAs you can see, `open` calls `parse!` for you, so that you can get down to business right away.\n\nIf you happen to prefer things DSL-style, the `open` method will also let you operate on the PSD object directly. Again, the call to `parse!` is handled for you.\n\n``` ruby\nrequire 'psd'\n\nPSD.open('path\u002Fto\u002Ffile.psd') do\n  p tree.to_hash\nend\n```\n\n### Traversing the Document\n\nTo access the document as a tree structure, use `psd.tree` to get the root node. From there, work with the tree using any of these methods:\n\n* `root`: get the root node from anywhere in the tree\n* `root?`: is this the root node?\n* `children`: get all immediate children of the node\n* `has_children?`: does this node have any children?\n* `childless?`: opposite of `has_children?`\n* `ancestors`: get all ancestors in the path of this node (excluding the root)\n* `siblings`: get all sibling tree nodes including the current one (e.g. all layers in a folder)\n* `next_sibling`: gets the sibling immediately following the current node\n* `prev_sibling`: gets the sibling immediately before the current node\n* `has_siblings?`: does this node have any siblings?\n* `only_child?`: opposite of `has_siblings?`\n* `descendants`: get all descendant nodes not including the current one\n* `subtree`: same as descendants but starts with the current node\n* `depth`: calculate the depth of the current node (root node is 0)\n* `path`: gets the path to the current node\n\nFor any of the traversal methods, you can also retrieve folder or layer nodes only by appending `_layers` or `_groups` to the method. For example:\n\n``` ruby\npsd.tree.descendant_layers\n```\n\nIf you know the path to a group or layer within the tree, you can search by that path. Note that this always returns an Array because layer\u002Fgroup names do not have to be unique.\n\n``` ruby\npsd.tree.children_at_path(\"Version A\u002FMatte\")\npsd.tree.children_at_path([\"Version A\", \"Matte\"])\n```\n\n### Layer Comps\n\nYou can also filter nodes based on a layer comp. To generate a new tree with layer visibility and position set according to the layer comp data:\n\n``` ruby\n# Get information about all the available layer comps\nputs psd.layer_comps\n\n# Can filter by name or by ID (obtained from above)\ntree = psd.tree.filter_by_comp('Version A')\nputs tree.children.map(&:name)\n```\n\nThis returns a new node tree and does not alter the original.\n\n### Accessing Layer Data\n\nTo get data such as the name or dimensions of a layer:\n\n``` ruby\npsd.tree.descendant_layers.first.name\npsd.tree.descendant_layers.first.width\n```\n\nPSD files also store various pieces of information in \"layer info\" blocks. Which blocks a layer has varies from layer-to-layer, but to access them you can do:\n\n``` ruby\npsd.tree.descendant_layers.first.text[:font]\n\n# Returns\n{:name=>\"HelveticaNeue-Light\",\n :sizes=>[33.0],\n :colors=>[[255, 19, 120, 98]],\n :css=>\n  \"font-family: \\\"HelveticaNeue-Light\\\", \\\"AdobeInvisFont\\\", \\\"MyriadPro-Regular\\\";\\nfont-size: 33.0pt;\\ncolor: rgba(19, 120, 98, 255);\"}\n```\n\n### Exporting Data\n\nWhen working with the tree structure, you can recursively export any node to a Hash.\n\n``` ruby\npp psd.tree.to_hash\n```\n\nWhich produces something like:\n\n``` ruby\n{:children=>\n  [{:type=>:group,\n    :visible=>false,\n    :opacity=>1.0,\n    :blending_mode=>\"normal\",\n    :name=>\"Version D\",\n    :left=>0,\n    :right=>900,\n    :top=>0,\n    :bottom=>600,\n    :height=>900,\n    :width=>600,\n    :children=>\n     [{:type=>:layer,\n       :visible=>true,\n       :opacity=>1.0,\n       :blending_mode=>\"normal\",\n       :name=>\"Make a change and save.\",\n       :left=>275,\n       :right=>636,\n       :top=>435,\n       :bottom=>466,\n       :height=>31,\n       :width=>361,\n       :text=>\n        {:value=>\"Make a change and save.\",\n         :font=>\n          {:name=>\"HelveticaNeue-Light\",\n           :sizes=>[33.0],\n           :colors=>[[255, 19, 120, 98]],\n           :css=>\n            \"font-family: \\\"HelveticaNeue-Light\\\", \\\"AdobeInvisFont\\\", \\\"MyriadPro-Regular\\\";\\nfont-size: 33.0pt;\\ncolor: rgba(19, 120, 98, 255);\"},\n         :left=>0,\n         :top=>0,\n         :right=>0,\n         :bottom=>0,\n         :transform=>\n          {:xx=>1.0, :xy=>0.0, :yx=>0.0, :yy=>1.0, :tx=>456.0, :ty=>459.0}},\n       :ref_x=>264.0,\n       :ref_y=>-3.0}]\n  }],\n:document=>{:width=>900, :height=>600}}\n```\n\nYou can also export the PSD to a flattened image. Please note that, at this time, not all image modes + depths are supported.\n\n``` ruby\npng = psd.image.to_png # reference to PNG data\npsd.image.save_as_png 'path\u002Fto\u002Foutput.png' # writes PNG to disk\n```\n\nThis uses the full rasterized preview provided by Photoshop. It does not use the built-in rendering engine (described below). If the file was not saved with Compatibility Mode enabled, this will return an empty image.\n\n### Preview Building\n\nYou can build previews of any subset or version of the PSD document using the built-in renderer. This is useful for generating previews of layer comps or exporting individual layer groups as images.\n\n``` ruby\n# Save a layer comp\npsd.tree.filter_by_comp(\"Version A\").save_as_png('.\u002FVersion A.png')\n\n# Generate PNG of individual layer group\npsd.tree.children_at_path(\"Group 1\").first.to_png\n```\n\n### Slices\n\nBecause slices are relative to the full document, you can access them directly on the `psd` object. Use `psd.slices` to get an array of all slices in the document.\n\n``` ruby\nslices = psd.slices\nslices.first.name #=> \"Logo\"\nslices.first.left #=> 20\nslices.first.width #=> 200\n```\n\nYou can also search for slices if you know their name or ID. Because slice names do not need to be unique, `slices_by_name` will always return an array of all matches.\n\n``` ruby\npsd.slice_by_id(2)\npsd.slices_by_name('Logo')\n```\n\nWhen you create a slice based off of a layer, Photoshop stores this relation in the file. If you have a slice that was created this way, you can easily get the associated layer.\n\n``` ruby\nslice = psd.slices_by_name('Logo').first\nslice.associated_layer #=> \u003CPSD::Node::Layer>\n```\n\nFinally, you can export slices as PNGs.\n\n``` ruby\npsd.slices.first.to_png #=> ChunkyPNG canvas\npsd.slices_by_name('Logo').first.save_as_png('Logo.png') #=> writes Logo.png\n```\n\n### Debugging\n\nIf you run into any problems parsing a PSD, you can enable debug logging via the `PSD_DEBUG` environment variable. For example:\n\n``` bash\nPSD_DEBUG=true bundle exec examples\u002Fparse.rb\n```\n\nIf you need to enable debugging programatically:\n\n``` ruby\nPSD.debug = true\n```\n\n## To-do\n\nThere are a few features that are currently missing from PSD.rb.\n\n* More image modes + depths for image exporting\n* Support for rendering all layer styles\n* Support for layer comp adjusted layer styles\n* Render engine fixes for groups with lowered opacity\n","PSD.rb 是一个用 Ruby 编写的 Photoshop 文件解析器，旨在轻松解析 PSD 文件。它能够将 Photoshop 文档转换为可管理的树状结构，并从中提取诸如文档结构、尺寸、图层\u002F文件夹信息（包括大小、位置、名称、可见性及不透明度）、字体数据（通过 psd-enginedata 支持）、颜色模式与位深度、矢量蒙版数据以及扁平化图像数据等关键信息。该项目支持 MRI 1.9.3, 2.0.0, 2.1.0 和 JRuby (1.9.3 模式) 环境下的测试运行。对于需要提高处理速度的 MRI Ruby 用户，项目还提供了 psd_native 作为加速选项。PSD.rb 适用于需要从 PSD 文件中读取和操作设计元素的各种开发场景，如自动化设计流程、图像处理脚本编写等。",2,"2026-06-11 03:14:50","top_language"]