ruby-on-railsrubyrubygemspsd

Not getting exact Text box Bounds using PSD.rb gem


I'm trying to parse the PSD file using PSD.rb gem.

When I'm trying to get the text box bounds, it is giving minimal bounding box for the text, not the actual text rectangle dimensions in the psd file.

Similar issue was posted here: https://github.com/layervault/psd.rb/issues/78 But, there is no proper solution for it. So, can anybody help me in finding the exact text box Bounds from PSD?

Thanks in advance!


Solution

  • Getting Height & Width information from the bounds object:

    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.