In this post i will explain how one leverages python to make base64 the tuxcards xml files, to be able to share them. This way you can share them without having to give many photos folder or paths at all, and be able to distribute them, in some cases even encrypt them.
(Example of an Manual that regards GPT technolgoy)
Python code:
def convert_image_to_base64(image_path):with open(image_path, "rb") as image_file:return base64.b64encode(image_file.read()).decode('utf-8')# Function to update the HTML content with Base64 encoded imagesdef update_img_src_with_base64(html_content):# Find all <img> tags with their src attributeimg_tags = re.findall(r'<img\s+[^>]*src=["\']([^"\']+)["\']', html_content)for img_path in img_tags:# Ensure the file exists before convertingif os.path.exists(img_path):base64_image = convert_image_to_base64(img_path)extension = img_path.split('.')[-1]mime_type = f"image/{extension}" if extension in ['jpeg', 'jpg', 'png', 'gif'] else "image/png"base64_data_url = f"data:{mime_type};base64,{base64_image}"html_content = html_content.replace(img_path, base64_data_url)return html_content# Function to process each HTML file and convert the entire content to Base64def process_html_files(file_paths, output_folder):# Create the output folder if it doesn't existif not os.path.exists(output_folder):os.makedirs(output_folder)for file_path in file_paths:# Read HTML file contentwith open(file_path, 'r', encoding='utf-8') as file:html_content = file.read()# Update image sources with Base64 encoded imagesupdated_html = update_img_src_with_base64(html_content)# Save the updated HTML file to the output folderoutput_file_path = os.path.join(output_folder, f"{os.path.basename(file_path).split('.')[0]}_base64.html")with open(output_file_path, 'w', encoding='utf-8') as output_file:output_file.write(updated_html)print(f"Processed {file_path} and saved as {output_file_path}")
Then we save the base64 xml file which has every file, and can be distributed and display images, without having to reference path or multiple folders of images.
Now the best part is when you encrypt using the Tuxcards feature it encrypts the base64 image, so it is also adding level of security.
That is all, for now. Making manuals with images, and encyrpting them to make it send to people, who both know the password.