def encode_files(image_in, data_in, image_out, format): image = Image.open(image_in) if not hasattr(data_in, 'read'): data_in = open(data_in, 'rb') data = data_in.read() if hasattr(image_out, 'write'): format = image.format stepic.encode_inplace(image, data) image.save(image_out, format)
def save_to_image(self): try: data = self.md5_hash + json.dumps(self.passwords_dict) except ValueError: print('password_dict not a valid json') exit(0) stepic.encode_inplace(self.image, data) assert stepic.decode(self.image) == data self.image.save(self.image_path) print("\nChanges saved in the image!\n")
def hideTextInImage(fileNameInput, fileNameOutput, textToWrite, verbose): """ Hide a text in an image that is read and written on disk. return : 0 if ok, 1 if problem with fileNameInput, 2 if problem with fileNameOutput, 3 if io problem parameters : - fileNameInput : path of the original file - fileNameOutput : path name of output file with text hidden inside - textToWrite : text string to hide in file - verbose : True if message can be written on stdout file """ cr = 0 if verbose: print("Enter in hideTextinImage()") print("fileNameInput=", fileNameInput) print("fileNameOutput=", fileNameOutput) print("textToWrite=", textToWrite) try: if fileNameInput: image = Image.open(fileNameInput) formatImage = image.format # v3.0 : stepic.encode_inplace should be an array of int dataIntArray = [ord(char) for char in textToWrite] print("image.mode", image.mode) stepic.encode_inplace(image, dataIntArray) if fileNameOutput: image.save(fileNameOutput, formatImage) else: cr = 2 else: cr = 1 except IOError as exc: print("exception =", exc) cr = 3 if verbose: print("Exit from hideTextinImage(), cr=", cr) return cr
def video(filename, username, t0): # Orignal Video original = VideoFileClip("static/videos/"+filename+".mp4") first_half = VideoFileClip("static/videos/"+filename+".mp4").subclip(0, t0) second_half = VideoFileClip("static/videos/"+filename+".mp4").subclip(t0+1, original.duration) original.save_frame("static/videos/frame.png", t=t0) img = Image.open("static/videos/frame.png").convert(mode='RGB') stepic.encode_inplace(img, username) msg = stepic.decode(img) print(msg) img.save("static/videos/frame.png") encoded_clip = ImageClip('static/videos/frame.png', duration=1) new_mov = CompositeVideoClip([first_half.set_start(0), encoded_clip.set_start(t0), second_half.set_start(t0+1)]) # Write the result to a file (many options available !) new_mov.write_videofile("static/"+username+"_"+filename+".avi", codec='png')
modulename = opt.CRYPT + "def" # [modulename]def.py globals()["crypt"] = __import__(modulename) imagem = opt.IMAGE file_in = opt.FILE file_out = opt.FILEOUT #main image_obj = Image.open(imagem) stepic._validate_image(image_obj) if opt.encode: if not file_out: file_out = "%s.hd" % (imagem) data = open(file_in, "r").read() data = crypt.main_encrypt(data) stepic.encode_inplace(image_obj, data) image_obj.save(file_out, image_obj.format) elif opt.decode: data = stepic.decode(image_obj) data = crypt.main_decrypt(data) if not file_out: print "------------BEGIN-----------\n", data, "------------END-------------" else: fileo = open(opt.FILEOUT, "w") fileo.write(data) fileo.close() else: parser.print_usage() image_obj.close()
def clear_all_data(self): data = '_' stepic.encode_inplace(self.image, data) self.image.save(self.image_path)