Add support for JPG images

This commit is contained in:
2023-06-01 21:25:45 +02:00
parent 060f44f57e
commit aa81ffc0a7
3 changed files with 17 additions and 3 deletions

View File

@@ -1,9 +1,19 @@
extends HTTPRequest
func GetRemoteImage(url):
var image = Image.new()
print("Fetching remote image %s" % url)
request(url)
var res = await request_completed
var image = Image.new()
image.load_png_from_buffer(res[3])
var magicBytes = res[3].slice(0,8)
print(magicBytes)
var error = null
if magicBytes == PackedByteArray([137, 80, 78, 71, 13, 10, 26, 10]):
print("Detected PNG File")
error = image.load_png_from_buffer(res[3])
if magicBytes == PackedByteArray([255, 216, 255, 224, 0, 16, 74, 70]):
print("Detected JPG File")
error = image.load_jpg_from_buffer(res[3])
if error != OK:
print("Error fetching image ", str(error))
return image