fix: support base64 encoded image_url (#872)
- Add support for base64 encoded image in OpenAI's image_url Co-authored-by: JustSong <39998050+songquanpeng@users.noreply.github.com>
This commit is contained in:
parent
c50c609565
commit
7772064d87
@ -15,6 +15,9 @@ import (
|
|||||||
_ "golang.org/x/image/webp"
|
_ "golang.org/x/image/webp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Regex to match data URL pattern
|
||||||
|
var dataURLPattern = regexp.MustCompile(`data:image/([^;]+);base64,(.*)`)
|
||||||
|
|
||||||
func IsImageUrl(url string) (bool, error) {
|
func IsImageUrl(url string) (bool, error) {
|
||||||
resp, err := http.Head(url)
|
resp, err := http.Head(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -44,9 +47,6 @@ func GetImageSizeFromUrl(url string) (width int, height int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetImageFromUrl(url string) (mimeType string, data string, err error) {
|
func GetImageFromUrl(url string) (mimeType string, data string, err error) {
|
||||||
// Regex to match data URL pattern
|
|
||||||
dataURLPattern := regexp.MustCompile(`data:image/([^;]+);base64,(.*)`)
|
|
||||||
|
|
||||||
// Check if the URL is a data URL
|
// Check if the URL is a data URL
|
||||||
matches := dataURLPattern.FindStringSubmatch(url)
|
matches := dataURLPattern.FindStringSubmatch(url)
|
||||||
if len(matches) == 3 {
|
if len(matches) == 3 {
|
||||||
|
Loading…
Reference in New Issue
Block a user