find_it_or_create_it / Convert_Base64_to_Image.py
manganapallydeepa's picture
Upload 8 files
32199b1 verified
raw
history blame contribute delete
564 Bytes
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!")