def append_exif(self, img_path): """ This method will read the Exif tags from the image and add them to the table. """ self.origin_img_path = img_path self.origin_cell_value = None reader = Reader(img_path) self.__set_sheet_data(reader.grouped_dict())
def save_exif(self, new_img_path="", origin_img_path=""): """ This method saves the Exif Tags back to the image. """ orig_path = self.__path(self.origin_img_path, origin_img_path) reader = Reader(orig_path) writer = Writer(reader.binary(), reader.dict()) target_path = self.__path(orig_path, new_img_path) logging.info("saving file: %s", target_path) data = self.sheet.get_sheet_data() writer.save(data, target_path)
def test_save_list(self): list = [["model", "bar"]] p = self.__path('modified.jpg') self.writer.save(list, p) keys = Reader(p).keys() self.assertTrue("model" in keys)
def read_icon(cls, icon_name): """ Read an icon from the assets. """ icon_path = os.path.join(os.path.dirname(__file__), "assets/" + icon_name) return Reader.read_image(icon_path)
def test_save_list_deleted_row(self): lst = [["model", "bar"], ["software", "python"]] p = self.__path('modified.jpg') writer = Writer(self.reader.binary(), Converter.to_dict(lst)) writer.save([["model", "bar"]], p) keys = Reader(p).keys() self.assertFalse("software" in keys)
class TestImageIO(unittest.TestCase): def __path(self, name): img = 'test/resources/' + name return os.path.realpath(img) def setUp(self): p = self.__path('lookup.jpg') self.reader = Reader(p) self.writer = Writer(self.reader.binary()) def test_keys(self): self.assertFalse(len(self.reader.keys()) == 0) def test_value(self): keys = self.reader.keys() val = self.reader.value(keys[0]) self.assertIsNotNone(val) def test_dict(self): res = self.reader.dict() self.assertFalse(len(res) == 0) def test_grouped_dict(self): lst = list(self.reader.grouped_dict().keys()) k = ExifFilter.read_only()[0] self.assertEqual(0, lst.index(k)) def test_save_list(self): list = [["model", "bar"]] p = self.__path('modified.jpg') self.writer.save(list, p) keys = Reader(p).keys() self.assertTrue("model" in keys) def test_save_list_deleted_row(self): lst = [["model", "bar"], ["software", "python"]] p = self.__path('modified.jpg') writer = Writer(self.reader.binary(), Converter.to_dict(lst)) writer.save([["model", "bar"]], p) keys = Reader(p).keys() self.assertFalse("software" in keys) def test_read_image(self): img = Reader.read_image(self.__path('lookup.jpg'), True) w, _ = img.size self.assertEqual(400, w)
def test_read_image(self): img = Reader.read_image(self.__path('lookup.jpg'), True) w, _ = img.size self.assertEqual(400, w)
def setUp(self): p = self.__path('lookup.jpg') self.reader = Reader(p) self.writer = Writer(self.reader.binary())
def read_image(cls, img_path): """ Read an image from the given path and scale it to fit max width/height. """ return Reader.read_image(img_path, True)