File size: 564 Bytes
2cfb01f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
import json
import base64
# Load JSON file
with open("bookings.json", "r") as f:
bookings = json.load(f)
# Take the first entry (or loop through all)
booking = bookings[0]
img_base64 = booking["productImage"]
# Remove the prefix if present (data:image/jpeg;base64,)
if "," in img_base64:
img_base64 = img_base64.split(",")[1]
# Decode Base64
img_bytes = base64.b64decode(img_base64)
# Save as image file
with open("recreated_image.jpg", "wb") as img_file:
img_file.write(img_bytes)
print("Image regenerated successfully!")
|