Added scaled ImageSource.
This commit is contained in:
parent
44220c8f9a
commit
5e735440ec
@ -3,6 +3,7 @@ package ui
|
|||||||
import (
|
import (
|
||||||
"image"
|
"image"
|
||||||
|
|
||||||
|
"github.com/nfnt/resize"
|
||||||
"opslag.de/schobers/zntg"
|
"opslag.de/schobers/zntg"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -45,3 +46,25 @@ func (s ImageSourceResource) CreateImage() (image.Image, error) {
|
|||||||
}
|
}
|
||||||
return value.(image.Image), nil
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user