mirror of
https://codeberg.org/PLG-Development/PLG-MuDiCS
synced 2026-07-06 00:47:09 +00:00
feat: image file preview
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package pkg
|
||||
|
||||
import "image"
|
||||
|
||||
func ResizeImage(img image.Image, newWidth, newHeight int) image.Image {
|
||||
srcBounds := img.Bounds()
|
||||
srcWidth := srcBounds.Dx()
|
||||
srcHeight := srcBounds.Dy()
|
||||
dst := image.NewRGBA(image.Rect(0, 0, newWidth, newHeight))
|
||||
for y := range newHeight {
|
||||
for x := range newWidth {
|
||||
srcX := x * srcWidth / newWidth
|
||||
srcY := y * srcHeight / newHeight
|
||||
c := img.At(srcBounds.Min.X+srcX, srcBounds.Min.Y+srcY)
|
||||
dst.Set(x, y, c)
|
||||
}
|
||||
}
|
||||
return dst
|
||||
}
|
||||
Reference in New Issue
Block a user