psd.rb icon indicating copy to clipboard operation
psd.rb copied to clipboard

text rectangles are incorrect

Open catmando opened this issue 11 years ago • 9 comments

I have a simple test registration document.

It contains a single text field called "text"

the dimensions and of the text in the document are much different from the original PSD, and from what is rendered.

The dimensions in the psd (viewed on a photoshop) are top = 1", left = 1", width=3", height=1"

The doc is 300 DPI, but the dimensions as read by psd.rb are top = 308, left = 464, width = 592, height = 101. (should be 300, 300, 900, 300)

For comparison the document has a grey image layer under the text with the same position and dimensions.

The photo layer position and dimensions ARE reported correctly by psd.rb.

My guess is that psd.rb is giving back some kind of minimal bounding box for the text, not the actual text rect in the psd file.

However as the psd file actually knows, and remembers the complete size of the text rect this looks like a problem.

The file can be accessed here: (I hope) http://832069e906a4cb1cbeba-356812981dd62c6b48c695351cd5444e.r90.cf2.rackcdn.com/uploads/background/psd/35/ce452152-cba1-4ca8-ade2-7d6d6e24c1e820141027-2-jzu8rh

catmando avatar Oct 27 '14 16:10 catmando

BTW - this is a "paragraph text" layer NOT a "point text" layer. It seems like psd.rb is treating the object as point text even if its paragraph text. I am pretty sure things work fine if its point text.

catmando avatar Oct 27 '14 16:10 catmando

Digging around in this I discovered this perhaps related discrepancy:

Adobe spec says that the "left, top, right, bottom" info are all 8 byte values, the parser is reading these as ints (which are too short and wrong type.)

Compare for example the transform values.

But its not that simple: patching the code to read left/top/right/bottom as double gives really strange values.

I am using this document as reference: http://www.adobe.com/devnet-apps/photoshop/fileformatashtml/#50577411_21585

spec might be wrong, as every place else where a rect is specified its done with 4 byte values, not 8.

catmando avatar Oct 27 '14 18:10 catmando

According to the PSD you gave me, the folder is named "text" but the actual text layer is named "Craig & Tessa". Are you looking at the correct position data?

meltingice avatar Oct 27 '14 18:10 meltingice

Yes I was giving the folder name, but the folder only contains the single layer, so the story is the same. Sorry about that.

catmando avatar Oct 27 '14 18:10 catmando

This seems extremely cludgy and brittle, but you can extract the correct dimensions (at least for simple cases) as follows:

      box_bounds = layer.type.engine_data.EngineDict["Rendered"]["Shapes"]["Children"][0]["Cookie"]["Photoshop"]["BoxBounds"]
      top = layer.text[:transform][:ty]
      left = layer.text[:transform][:tx] 
      height = box_bounds[3] 
      width = box_bounds[2]

This only seems to work if layer.type.engine_data.EngineDict["Rendered"]["Shapes"]["Children"][0]["ShapeType"]==1 which I am guessing means the text block is a paragraph

catmando avatar Oct 27 '14 19:10 catmando

I'm also facing the same issue. The solution provided by @catmando is not working for me all the times. I even tried in latest version of PSD.rb gem (3.9.0).

Can anybody provide the solution for this?

Thanks in advance.

sanjithg avatar Apr 08 '18 18:04 sanjithg

@sanjithg @dwillist might be able to check in our code and see if the above hack is still being used, or perhaps it changed slightly...

catmando avatar Apr 18 '18 02:04 catmando

We still use this exact same hack.

dwillist avatar Apr 18 '18 13:04 dwillist

Below logic given me the exact values for me.

bounds = layer.adjustments[:type].data[:text]["bounds"]
layer_tree = layer.to_hash
transform = layer_tree[:text][:transform]

top = transform[:ty] + bounds["Top "][:value]
left = transform[:tx]
width = bounds["Rght"][:value]
height = bounds["Btom"][:value] - bounds["Top "][:value]

Thanks.

sanjithg avatar Apr 18 '18 13:04 sanjithg