1

I'm flattening a vector from a design tool (Sketch) to a PNG. A vector may have a shadow:

enter image description here

In this case the X and Y before flattening are 100x100 and the width and height before flattening are 100x100 too.

For automation reasons, I am automatically performing this vector to PNG flattening in the background (it's a CLI running on a server). The tool then gives me the PNG's new width and height, but unlike in the image below, the new or delta X and Y are unknown:

enter image description here

As you can see above, sometimes these vectors have shadows which will cause the frame of the image to be greater when flattened, such that the shadow is included in the exported image. However, this also means that the X and Y of the new frame have to be adjusted, such that the rendered portion of the new frame is still positioned at its original location.

That's why the new X and Y are 29x44 (with width and height 233x244).

The question is how to compute the new or delta X and Y based on the original vector's properties (incl. shadow props x, y, blur, spread) and/or the new flattened image's width/height (which are known).

Summary

I need to compute the delta X and Y such that the position of the rendered image is the same as before its frame was changed in size to include the shadow in its flattened form.

Take this test case:

Before flattening

frame x = 100
frame y = 100
frame width = 100
frame height = 100
shadow x = 0
shadow y = 20
shadow blur = 80
shadow spread = 0

after flattening:

frame x = 29 (*) 
frame y = 44 (*)
frame width = 233
frame height = 244

I have all of the above values EXCEPT the after flattening frame x and y (marked with *). How do I develop a formula that computes this X, Y delta from the vector's frame and shadow properties and/or the new PNG's frame width/height?

Tom
  • 8,536
  • 31
  • 133
  • 232
  • This is entirely up to the specifications of the application that draws the shadow. But I would assume that the offset is linear in blur and spread (with different factors, probably around 3 and 1). Try a few examples and see if you can see any relationship. There is really nothing one could do from afar without knowing anything about the program. – Nico Schertler Apr 09 '19 at 02:02

0 Answers0