def steg(cover_path, hidden_path): ''' Function to hide data (either an image or text) within another image INPUT: string, path to the cover image; string, path to the hidden data OUTPUT: a new image with the hidden data encoded in the least significant bits ''' if hidden_path[-4:] == '.txt': text.encrypt(cover_path, hidden_path) else: image.merge(cover_path, hidden_path)
def testImageMergeLimit(self): MAX_IMAGES = 1024 # this one shouldn't throw. It's a bit slow, disable for faster # testing. if True: images = list(itertools.repeat( self._getImg("img1.png"), MAX_IMAGES)) merge(images) def doTest(): images = list(itertools.repeat( self._getImg("img1.png"), MAX_IMAGES + 1)) merge(images) self.assertRaises(SystemError, doTest)
def merge(self, tiles, params): images = [] for t in tiles: (format, data) = self.service.renderTile(t, params.has_key('FORCE')) if data is None: continue images.append(data) if not images: return (format, None) import image_merge preserve_colors = self.service.metadata.get( "image_merge_preserve_colors") in ("true", "on", "yes", "1") return (format, image_merge.merge(images, preserve_colors))
def merge_pixels(input_pixels, preserve_colors, expected_output_pixel): images = [] for p in input_pixels: pil_img = Image.new("RGBA", (1, 1)) pil_img.putdata([p]) buffer = StringIO.StringIO() pil_img.save(buffer, "PNG") buffer.seek(0) images.append(buffer.read()) result = merge(images, preserve_colors=preserve_colors) self.assertPNGImage(result) pil_result = Image.open(StringIO.StringIO(result)) self.assertEquals(pil_result.getdata()[0], expected_output_pixel)
def testMergeImage(self): img = merge([self._getImg("img1.png")]) self.assertPNGImage(img) img = merge([self._getImg("img1.png"), self._getImg("img2.png")]) self.assertPNGImage(img)
def testInvalidParams(self): self.assertRaises(TypeError, lambda: merge(1)) self.assertRaises(TypeError, lambda: merge("foo", "bar", [])) self.assertRaises(SystemError, lambda: merge([])) self.assertRaises(TypeError, lambda: merge([1])) self.assertRaises(TypeError, lambda: merge(["foo", "bar", []]))
def doTest(): merge([self._getImg("img1.png"), self._getImg("img1-10x10.png")])
def doTest(): merge([self._getImg("img1.png"), "foo"])
def testUnsupportedFormat(self): self.assertRaises(SystemError, lambda: merge(["foo"])) def doTest(): merge([self._getImg("img1.png"), "foo"]) self.assertRaises(SystemError, doTest)
def doTest(): images = list(itertools.repeat( self._getImg("img1.png"), MAX_IMAGES + 1)) merge(images)