Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # The decode py for the extracting data from an image embedded with data
- # MD Harrington Kent London UK 12-09-2024 Time 1:56
- # Facebook https://www.facebook.com/mark.harrington.14289
- # Now Improved much more This is just so cool
- # Instagram https://www.instagram.com/markukh2021/
- # Homesite (Still busy with this at present ) https://eliteprojects.x10host.com/
- # Github https://github.com/markh2024 && https://github.com/markh2016
- # Codeshare https://codeshare.io/codes
- # To most this would appear as a graph but , ha , ha Alas it is not and so I win again, eh , eh , eh
- # Who would never even think anything of this ? Not to many by the looks of this
- from PIL import Image, PngImagePlugin
- import matplotlib.pyplot as plt
- import time
- import datetime
- import os # For clearing the screen
- import platform # To detect the OS
- # Function to clear the screen based on the OS
- def clear_screen():
- # Detect the OS and clear screen appropriately
- if platform.system() == "Windows":
- os.system('cls')
- else:
- os.system('clear')
- def slow_print(text, color=None):
- if color:
- print(f"\033[{color}m", end="") # Set the color (e.g., '91' for red)
- for char in text:
- print(char, end='', flush=True)
- time.sleep(0.05) # Slow print effect
- if color:
- print("\033[0m", end="") # Reset color to default after text
- print() # New line after the text
- # Function to read ASCII values from image metadata and reconstruct the original sentence
- def read_ascii_from_image(image_path):
- try:
- # Open the image and access the metadata
- img = Image.open(image_path)
- # Display the image
- plt.imshow(img)
- plt.axis('off') # Hide axis for better display
- plt.title("Loaded Image with Embedded data")
- plt.show()
- # Extract metadata
- metadata = img.info
- # Extract the ASCII values stored as metadata
- if "ASCII Values" in metadata:
- ascii_values_str = metadata["ASCII Values"]
- slow_print(f"Extracted data values: {ascii_values_str}", color="45")
- # Convert the ASCII values string back into a list of integers
- ascii_values = list(map(int, ascii_values_str.split(',')))
- # Reconstruct the original message from the ASCII values
- original_message = ''.join(chr(value) for value in ascii_values)
- slow_print(f"Reconstructed message: {original_message}", color="96")
- else:
- slow_print("No ASCII values found in the image metadata.", color="90")
- except FileNotFoundError:
- print(f"Error: Image file '{image_path}' not found.")
- except Exception as e:
- print(f"An error occurred: {e}")
- if __name__ == "__main__":
- current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
- slow_print(f"\n\nProgram that decodes the image thank you and now it's easy. There you go, MD Harrington. {current_time}", color="92")
- # Provide the path to the image that contains the embedded ASCII values
- image_path = "ascplot.png" # Make sure the image path is correct
- read_ascii_from_image(image_path)
- slow_print(f"\n\nProgram exited gracefully, thank you MD Harrington. {current_time}", color="92")
- time.sleep(3)
- clear_screen()
- ## Enjoy as I have many more ideas to put into place It pays to listen to some people and now you see why
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement