Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to generate an .svg file from a greyscale image #2

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
[grey2svg] add image downscaling
  • Loading branch information
karimkfoure committed Jun 28, 2021
commit ef96876c4bce02b9c96ecba741808f10bc01c426
21 changes: 17 additions & 4 deletions cmd/gray2svg/main.go
Original file line number Diff line number Diff line change
@@ -9,23 +9,36 @@ import (
"os"
"strconv"

"github.com/disintegration/imaging"
"github.com/fogleman/gg"
"github.com/fogleman/terrarium"
"github.com/llgcode/draw2d/draw2dsvg"
)

const (
Steps = 100
Size = 1600
Padding = 0
LineWidth = 1
Steps = 100 // Z slice step size
ImageDownscalingFactor = 1 // 1x = original quality, 0.5x = half-resolution (experimental. removes detail from original image to smoothen output)
Size = 10000 // size in px
Padding = 0
LineWidth = 1
)

func main() {
// validate const
if ImageDownscalingFactor > 1 {
panic("ImageDownscalingFactor must be <= 1")
}
// load image
src, err := gg.LoadImage(os.Args[1])
if err != nil {
panic(err)
}
// apply downscaling
if ImageDownscalingFactor < 1 {
newWidth := int(float32(src.Bounds().Dx()) * ImageDownscalingFactor)
newHeight := int(float32(src.Bounds().Dy()) * ImageDownscalingFactor)
src = imaging.Resize(src, newWidth, newHeight, imaging.NearestNeighbor)
}

gray, _ := ensureGray16(src)
w := gray.Bounds().Size().X