// fetchOverlay tries to retrieve and decode a png image from the given path.
// If the path is a remote URL, then it is fetched, otherwise it is assumed that
// the path is a local file.
fetchOverlay tries to retrieve and decode a png image from the given path.
If the path is a remote URL, then it is fetched, otherwise it is assumed that
the path is a local file.
// fetchOverlay tries to retrieve and decode a png image from the given path . // If the path is a remote URL then it is fetched otherwise it is assumed that // the path is a local file .
func fetchOverlay(path string) (image.Image, error) {
	if isValidUrl(path) {
		resp, err := http.Get(path)
		if err != nil {
			return nil, fmt.Errorf("failed to fetch overlay image from '%s' | %w", path, err)
		}
		if resp.StatusCode != http.StatusOK {
			return nil, fmt.Errorf("failed to fetch overlay image from '%s' | Unexpected response status: %s", path, resp.Status)
		}
		defer resp.Body.Close()
		img, err := png.Decode(resp.Body)
		if err != nil {
			return nil, fmt.Errorf("failed to decode overlay image | %w", err)
		}
		return img, nil
	} else {
		data, err := os.Open(path)
		if err != nil {
			return nil, fmt.Errorf("failed to open local overlay image at '%s' | %w", path, err)
		}
		defer data.Close()
		img, err := png.Decode(data)
		if err != nil {
			return nil, fmt.Errorf("failed to decode overlay image | %w", err)
		}
		return img, nil
	}
}
func fetchOverlay ( path string ) ( image . Image , error ) { if isValidUrl ( path ) { resp , err := http . Get ( path ) if err != nil { return nil , fmt . Errorf ( " " , path , err ) } if resp . StatusCode != http . StatusOK { return nil , fmt . Errorf ( " " , path , resp . Status ) } defer resp . Body . Close ( ) img , err := png . Decode ( resp . Body ) if err != nil { return nil , fmt . Errorf ( " " , err ) } return img , nil } else { data , err := os . Open ( path ) if err != nil { return nil , fmt . Errorf ( " " , path , err ) } defer data . Close ( ) img , err := png . Decode ( data ) if err != nil { return nil , fmt . Errorf ( " " , err ) } return img , nil } }
fetchOverlay tries to retrieve and decode a png image from the given path.
fetchOverlay tries to retrieve and decode a png image from the given path .