Products |
Signals Inventa, Vitro Vivo, Research Suit |
Keywords: Base64 Encoding, Signals Spotfire, Signals Data Factory, PNG to Base64, JPEG to Base64, Image Upload, Data Conversion
Description:
This article outlines the process for converting PNG and JPEG images to Base64 encoding to facilitate their use in Signals Spotfire and Signals Data Factory. Since these platforms do not support direct image file uploads, converting images to Base64 allows for the inclusion of image data in a format that can be handled by these systems. The process involves using Python to read image files from folder, encode them in Base64, and prepare the data for upload.
Resolution:
Use the following Python script to convert your images to Base64 and prepare the data:
import os
import pandas as pd
import base64
def image_to_base64(image_path):
"""Convert an image file to a Base64 encoded string."""
with open(image_path, "rb") as img_file:
encoded_string = base64.b64encode(img_file.read())
return encoded_string.decode('utf-8')
def images_in_folder_to_base64(folder_path):
"""Convert all images in a folder to Base64 and return as a dictionary."""
base64_images = {}
for filename in os.listdir(folder_path):
if filename.endswith(".jpg") or filename.endswith(".png"):
image_path = os.path.join(folder_path, filename)
base64_images[filename] = image_to_base64(image_path)
return base64_images
# Define the folder path containing images
folder_path = r"C:\Users\YourUsername\Path\To\Images" # Change this path to your folder
# Convert images in the folder to Base64
base64_images = images_in_folder_to_base64(folder_path)
# Create a DataFrame
df = pd.DataFrame({"Filename": list(base64_images.keys())})
df["Base64"] = df["Filename"].map(base64_images)
Replace r"C:\Users\YourUsername\Path\To\Images"
with the path to your folder containing images.
You can upload the data table to the Signals Data Factory using the Publish Measurement App.
Please find the attached Dashboard for reference.