#Convert drawings to image
1 messages ยท Page 1 of 1 (latest)
continuing thread from here #module-development message
Convert drawings to image
i am seeing identical values for my tile width/height and drawing.shape.width/height
which are different from drawing.document.shape
I'm testing with this thick drawing now. it's positioned at 100x100 precisely, and console logs show:
when what I want is numbers that are approximately:
[60, 95, '//', 370 - 60, 260 - 95]
so you want the tile to be placed in the exact place the drawing was?
yup, as a final goal
I mean I want it to visually replace the drawing, I don't care if there's extra invisible padding
i made a very square one to test, and is the offset something like half the stroke width?
it's at most that much, yeah, in each direction
meanwhile I'm having some success and some failure with adding a "safety margin" to the container before giving it the children, and/or adding extra x/y offset per child to fix it
and y
drawing.shape.data.x is exactly half the stroke width smaller than the tile.x
and similar for y

is d the document or the placeable?
the placeable drawing
...
that is when i realize i am looking at v11 as that is where i had my macro.
and you tell me you are in v12?
time to move over my macro to the current version of Foundry ๐
get with the times, old man!
i have servers from v9 to v13 ๐
that's fancy and admittedly useful (but also I'm glad I don't make an effort to maintain my own modules for v11 anymore, only v12+)
good decision ๐
ok
try
d.shape.canvasBounds
that seems to be where the tile has to go
of course that is not too viable with multiple drawings
my attempt of adding safety margins should have worked, but I ran into the problem that for some reason the rendered image always ignored left and top padding, so I couldn't align it after all
no it's totally viable, I just tested it and it works
just needed to change the boundary check to this:
const left = drawings.reduce((min, drawing) => Math.min(min, drawing.shape.canvasBounds.x), Infinity)
const top = drawings.reduce((min, drawing) => Math.min(min, drawing.shape.canvasBounds.y), Infinity)
const right = drawings.reduce((max, drawing) => Math.max(max, drawing.shape.canvasBounds.x + drawing.shape.canvasBounds.width), -Infinity)
const bottom = drawings.reduce((max, drawing) => Math.max(max, drawing.shape.canvasBounds.y + drawing.shape.canvasBounds.height), -Infinity)
yup, which I already do
okay great, that's 2 bugs laregely fixed!
next up, bug 3, rotation is ignored
should be easier
i wish i had your confidence when it came to rotations ๐
...don't scare me
good luck, i would be of no help for this part
newShape.rotation = drawing.shape.rotation
easy peasy
wait hold on... this messes with the left and top. nnoooo
damn it this somehow messes with scale too?!
okay I got a "good enough" solution that just occasionally cuts off pieces of the rotated drawings, and I will consider this acceptable
hold up, this doesn't work with text drawings, their drawing.shape.canvasBound is not defined...
no
normally I don't need to worry about it that much, because text borders width doesn't make them extend past their frame (unlike normal strokes), which is convenient
I do need to handle rotated texts, though... just in case
what the... and you're on v12?
weird...
it's not because of the outer bounds, looks like
well... I found an alternative path
d.frame.getLocalBounds() added onto the base x/y or the shape x/y probably
that is a local position you can make that into a global by doing some function...
canvas.app.stage.getGlobalPosition(localbounds)
doesn't seem to fit with my numbers
hmm
oh yeah global is the wrong thing... >.< that is screen position
related to.... not is
getting closer, but not quite there...
that is because the text has different coords from the square around it
the text is a child of the shape
so its coords are relative to the square
if that makes sense
yeah... it makes sense but wrapping my code around it does not