Skip to content

Commit

Permalink
✨ Use resvg instead of magick for svg thumbnailing
Browse files Browse the repository at this point in the history
  • Loading branch information
gwennlbh committed Jan 2, 2025
1 parent 4219f77 commit c9a61b3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions thumbnails.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ func (ctx *RunContext) MakeThumbnail(media Media, targetSize int, saveTo string)
return ctx.makeGifThumbnail(media, targetSize, saveTo)
}

if media.ContentType == "image/svg+xml" {
return ctx.makeSvgThumbnail(media, targetSize, saveTo)
}

if strings.HasPrefix(media.ContentType, "image/") {
return run("magick", media.DistSource.Absolute(ctx), "-resize", fmt.Sprint(targetSize), saveTo)
}
Expand All @@ -58,6 +62,11 @@ func (ctx *RunContext) MakeThumbnail(media Media, targetSize int, saveTo string)

}

func (ctx *RunContext) makeSvgThumbnail(media Media, targetSize int, saveTo string) error {
// Use resvg instead of magick, because magick delegates to inkscape which is not reliable in parallel (see https://gitlab.com/inkscape/inkscape/-/issues/4716)
return run("resvg", "--width", fmt.Sprint(targetSize), "--height", fmt.Sprint(targetSize), media.DistSource.Absolute(ctx), saveTo)
}

func (ctx *RunContext) makePdfThumbnail(media Media, targetSize int, saveTo string) error {
// If the target extension was not supported, convert from png to the actual target extension
temporaryPng, err := ioutil.TempFile("", "*.png")
Expand Down

0 comments on commit c9a61b3

Please sign in to comment.