I want to have a python script that creates a new image from the image data that is already embedded in the script itself
Latest efforts:
instead of just pasting the image data into my new script file (because it doesn’t work) ive decided to make a certain python script that reads in the data from the image on my desktop and stores it as a variable called “data”, then writes a new python script and incorporates the “data” variable in with it.
define The original image that resides on my desktop
original = “C:\users\joe\desktop\galaxy.png”
Open the original image and set its data as a variable called “data”
pic = open(original, “rb”)
data = pic.read()
pic.close()
set up the code for the new script which includes “data”
binary data I pasted into the script from having opened the image with notepad
ahm… that’s not going to work?! You will lose most of the information, as there’s not a printable character for every ascii/unicode letter and text editors usually replace them. Furthermore, to have a string with binary data in it in python, you needed that string to be py-encoded (at least the non-printable chars), e.g. “\x10\x13”
sure there is, but your approach puzzles me a bit…
do you only have that image data pasted into notepad? don’t you have it anywhere else? If the original data is still in the clipboard, use HxD or any hex editor to paste and save to file.
uhm… well of course it fails, 'cause you mix python with binary data without escaping or encoding it. If all you wanna do is to store the content of a file inside a python script .py, do this:
Thanks so much man. Also, using python 2.6 as i have been, i have tweeked your given code that runs without having to use ‘r’ or ‘b’. Is there any reason why the below code wouldnt be as good as the original code you shared with me?