diff --git a/ui/imagesource.go b/ui/imagesource.go index adab905..25aae8f 100644 --- a/ui/imagesource.go +++ b/ui/imagesource.go @@ -3,6 +3,7 @@ package ui import ( "image" + "github.com/nfnt/resize" "opslag.de/schobers/zntg" ) @@ -45,3 +46,25 @@ func (s ImageSourceResource) CreateImage() (image.Image, error) { } return value.(image.Image), nil } + +func ImageSourceFromResources(res Resources, name string) ImageSourceResource { + return ImageSourceResource{Resources: res, Name: name} +} + +func Scaled(source ImageSource, width, height int) ImageSource { + return scaledImageSource{ImageSource: source, width: width, height: height} +} + +type scaledImageSource struct { + ImageSource + + width, height int +} + +func (s scaledImageSource) CreateImage() (image.Image, error) { + im, err := s.ImageSource.CreateImage() + if err != nil { + return nil, err + } + return resize.Resize(uint(s.width), uint(s.height), im, resize.Bicubic), nil +}