// Package area provides functions working with image areas. package area import ( "fmt" "image" ) // Size returns the size of the provided area. func Size(area image.Rectangle) image.Point { return image.Point{ area.Dx(), area.Dy(), } } // FromSize returns the corresponding area for the provided size. func FromSize(size image.Point) (image.Rectangle, error) { if size.X < 0 || size.Y < 0 { return image.Rectangle{}, fmt.Errorf("cannot convert zero or negative size to an area, got: %+v", size) } return image.Rect(0, 0, size.X, size.Y), nil }