diff --git a/image.go b/image.go index 1851b07..7786dcc 100644 --- a/image.go +++ b/image.go @@ -8,7 +8,6 @@ import ( "fmt" "io" "net/http" - "net/url" "os" "path/filepath" "strings" @@ -196,9 +195,8 @@ func ImageToBase64(imageURL string) (string, error) { return "", fmt.Errorf("unsupported image format: %s", ext) } - //Check if the imageURL is a valid URL or a path to a local file - if _, err := url.ParseRequestURI(imageURL); err == nil { - // If it's a valid URL, download the image and convert it to base64 + // Check if the imageURL is a web URL by looking for http(s) prefix + if strings.HasPrefix(imageURL, "http://") || strings.HasPrefix(imageURL, "https://") { return handleImageFromURL(imageURL) } diff --git a/image_test.go b/image_test.go index bf81423..a956137 100644 --- a/image_test.go +++ b/image_test.go @@ -231,6 +231,12 @@ func TestImageToBase64Encoding(t *testing.T) { want: "data:image/png;base64,", wantErr: false, }, + { + name: "Local image full path", + imgURL: "/Users/vein/Downloads/wallpapers/PINK-FLOYD.png", + want: "data:image/png;base64,", + wantErr: false, + }, { name: "WebP image from Google", imgURL: "https://www.gstatic.com/webp/gallery/1.webp",