vpdn/MMLayershots

Crop layers to bounding box

vpdn opened this issue · 1 comments

vpdn commented

Currently all layers are rendered in full size of the window, which makes the resulting psd unnecessarily big. The file is automatically trimmed by photoshop, but only after the user opens and resaves the file. We need to find a way to trim the whitespace out to make the PSD smaller and easier to transport via Email.

One way of doing it would be to:

  • Inspect the generated layer images and scan line by line. This has the advantage of detecting empty layers (i.e. layers with only transparent pixels), but will require image analysis on each layer.
  • A more elegant and efficient method would be to calculate the required layer bounds by recursing through the child layers and 'unioning' the layer rects. This however won't detect empty (transparent) layers

A combination of both might be the best approach.

Hi, did just make a PR on this.
My first optimization is on layer content. Layer are no longer rendered from there parent, but directly on them, and I did compute offset from parent layer
Generated PSD files size is divided by 3 to 4 with my tests.
Next step is to crop generated document size in

SFPSDWriter, - (SFPSDLayer *)addLayerWithCGImage:(CGImageRef)image andName:(NSString*)name andOpacity:(float)opacity andOffset:(CGPoint)offset

But all my tests did fail. Still working on it.

See PR #20