Skip to content

Commit

Permalink
resize composite frame
Browse files Browse the repository at this point in the history
  • Loading branch information
logica0419 committed Dec 10, 2023
1 parent 0daa012 commit e9ddab2
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions service/imaging/processor_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,24 @@ func (p *defaultProcessor) FitAnimationGIF(src io.Reader, width, height int) (*b
BackgroundIndex: srcImage.BackgroundIndex,
}

for _, srcFrame := range srcImage.Image {
var tempCanvas *image.NRGBA
for i, srcFrame := range srcImage.Image {
srcBounds := srcFrame.Bounds()
destBounds := image.Rect(
int(math.Round(float64(srcBounds.Min.X)*ratio)),
int(math.Round(float64(srcBounds.Min.Y)*ratio)),
int(math.Round(float64(srcBounds.Max.X)*ratio)),
int(math.Round(float64(srcBounds.Max.Y)*ratio)),
)
fittedImage := imaging.Resize(srcFrame.SubImage(srcBounds), destBounds.Dx(), destBounds.Dy(), mks2013Filter)

if i == 0 {
tempCanvas = image.NewNRGBA(srcBounds)
}
draw.Draw(tempCanvas, srcBounds, srcFrame, srcBounds.Min, draw.Over)

fittedImage := imaging.Resize(tempCanvas, width, height, mks2013Filter)
destFrame := image.NewPaletted(destBounds, srcFrame.Palette)
draw.Draw(destFrame, destBounds, fittedImage, image.Point{}, draw.Over)
draw.Draw(destFrame, destBounds, fittedImage.SubImage(destBounds), destBounds.Min, draw.Src)
destImage.Image = append(destImage.Image, destFrame)
}

Expand Down

0 comments on commit e9ddab2

Please sign in to comment.