#Convert drawings to image

1 messages ยท Page 1 of 1 (latest)

mortal cliff
#

Convert drawings to image

barren abyss
#

i am seeing identical values for my tile width/height and drawing.shape.width/height

#

which are different from drawing.document.shape

mortal cliff
#

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]

barren abyss
#

so you want the tile to be placed in the exact place the drawing was?

mortal cliff
#

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

barren abyss
#

i made a very square one to test, and is the offset something like half the stroke width?

mortal cliff
#

it's at most that much, yeah, in each direction

barren abyss
#

that overlaps the both perfectly

#

now with a curly drawing...

#

.data.x

mortal cliff
#

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

barren abyss
#

and y

#

drawing.shape.data.x is exactly half the stroke width smaller than the tile.x

#

and similar for y

mortal cliff
barren abyss
#

is d the document or the placeable?

mortal cliff
#

the placeable drawing

barren abyss
#

...

#

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?

mortal cliff
#

...yes

#

๐Ÿ˜‚

barren abyss
#

time to move over my macro to the current version of Foundry ๐Ÿ˜„

mortal cliff
#

get with the times, old man!

barren abyss
#

i have servers from v9 to v13 ๐Ÿ˜„

mortal cliff
#

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+)

barren abyss
#

good decision ๐Ÿ˜„

#

ok

#

try

#

d.shape.canvasBounds

#

that seems to be where the tile has to go

mortal cliff
#

looks promising!

#

works perfectly

barren abyss
#

of course that is not too viable with multiple drawings

mortal cliff
mortal cliff
#

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)
barren abyss
#

ah good

#

and then use left and top for the tile creation?

mortal cliff
#

yup, which I already do

#

okay great, that's 2 bugs laregely fixed!

#

next up, bug 3, rotation is ignored

#

should be easier

barren abyss
#

i wish i had your confidence when it came to rotations ๐Ÿ˜„

mortal cliff
#

...don't scare me

barren abyss
#

good luck, i would be of no help for this part

mortal cliff
#

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

mortal cliff
barren abyss
#

...

#

wait it does for me?

#

bounds

#

canvasBounds

#

did you miss the s?

mortal cliff
#

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

barren abyss
mortal cliff
#

what the... and you're on v12?

barren abyss
#

yup

#

you can see the edge of a region on the screen shot ๐Ÿ˜„

mortal cliff
#

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

barren abyss
#

that is a local position you can make that into a global by doing some function...

#

canvas.app.stage.getGlobalPosition(localbounds)

mortal cliff
#

doesn't seem to fit with my numbers

barren abyss
#

hmm

#

oh yeah global is the wrong thing... >.< that is screen position

#

related to.... not is

mortal cliff
#

getting closer, but not quite there...

barren abyss
#

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

mortal cliff
#

yeah... it makes sense but wrapping my code around it does not