creativescala / doodle

Compositional vector graphics in Scala / Scala.JS
https://creativescala.org/doodle/
Apache License 2.0
327 stars 75 forks source link

Image saved to file does not have size of Frame #141

Closed hmf closed 10 months ago

hmf commented 10 months ago

I am trying to generate a sequence of images with a specific size. The size is required because these images will be used for machine learning. I used the following code do set up and draw on a frame:

    val picture = Picture.circle(100).strokeColor(Color.crimson)
    val frame = Frame.default.withSize(width , height).withBackground(Color.white)

    // Using IO
    val r = picture.drawWithFrameToIO(frame)
    r.unsafeRunSync()

The output to screen seems to be what I want. However, when I save this picture the file seems to contain a cropped image with a give margin. Here is what I do:

    val out1 = os.pwd / "circle.png"
    println(out1.toIO)
    picture.write[Png](out1.toIO)

My question is, how can I save the picture with the Frame size? Note that I also need to generate images were shapes appear in random positions and may be clipped if too close to the border.

TIA

hmf commented 10 months ago

I was looking through the code and found def write[A](file: File, frame: Frame, picture: Picture[A]): IO[A] . This seems to work:

    val out1 = os.pwd / "circle.png"
    picture.write[Png](out1.toIO, frame)

So my error. VSCode IDE intellisense does not show WriterOpsHelper and WriterIOOpsHelper methods unless I specifically look for the applymethod.

Apologies for the noise. Closing.