Skip to content

Commit

Permalink
Update svg document size.
Browse files Browse the repository at this point in the history
  • Loading branch information
egonelbre committed Dec 21, 2016
1 parent 7f2487c commit 4507297
Show file tree
Hide file tree
Showing 18 changed files with 718 additions and 511 deletions.
23 changes: 19 additions & 4 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import (
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"sort"
"strconv"
"strings"

"image"
Expand All @@ -22,7 +24,7 @@ const (
ThumbnailSize = 128
MaxColumns = 6

CollageFolder = "collage"
InkscapePath = `c:\Program Files\Inkscape\inkscape.exe`
)

const README_HEADER = `
Expand Down Expand Up @@ -167,6 +169,13 @@ type Thumbs struct {
Links []ImageLink
}

func (thumbs *Thumbs) ExportSVG(actual, out string) {
os.MkdirAll(filepath.Dir(out), 0755)
// inkscape -h 128 -e hiking.png hiking.svg
cmd := exec.Cmd(InkscapePath, "-h", strconv.Itoa(thumbs.Size), "-e", out, actual)
cmd.Run()
}

func (thumbs *Thumbs) Downscale(actual, out string, m image.Image) image.Image {
targetSize := image.Point{0, thumbs.Size}
targetSize.X = m.Bounds().Dx() * thumbs.Size / m.Bounds().Dy()
Expand Down Expand Up @@ -212,15 +221,21 @@ func MakeThumbs(name, folder, output string) *Thumbs {
for _, file := range files {
path := filepath.Join(folder, file.Name())
log.Printf("> add: %v\n", path)

outpath := filepath.Join(output, file.Name())
outpath = ReplaceExt(outpath, ".png")

if filepath.Ext(path) == ".svg" {
thumbs.ExportSVG(path, outpath)
continue
}

m, err := LoadImage(path)
if err != nil {
log.Printf("> error: %v\n", err)
continue
}

outpath := filepath.Join(output, file.Name())
outpath = ReplaceExt(outpath, ".png")

out := thumbs.Downscale(path, outpath, m)
if err := SavePNG(out, outpath); err != nil {
log.Printf("> error: %v\n", err)
Expand Down
71 changes: 43 additions & 28 deletions vector/adventure/hiking.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4507297

Please sign in to comment.