def watermark_photo(input_image_path, output_image_path, watermark_image_path): base_image = Image.open(input_image_path).convert('RGB') base_image = imdirect.autorotate(base_image) watermark = Image.open(watermark_image_path) w, h = base_image.size wm, wh = watermark.size base_image.paste(watermark, (w - wm, h - wh)) base_image.save(output_image_path)
def auto_rotate(filepath): """ Rotates an Image based on the EXIF-Information :param filepath: Path of the Image :return: """ img = Image.open(filepath) img_rotated = imdirect.autorotate(img) img_rotated.save(filepath)
def test_autorotate_1(): image_path = os.path.join(this_dir, 'testfile_6.jpg') img = Image.open(image_path) assert img.width == 300 assert img.height == 225 assert img._getexif().get(274) == 6 img_rot = imdirect.autorotate(img) assert img_rot.width == 225 assert img_rot.height == 300 assert not hasattr(img_rot, '_getexif')
def test_autorotate_1(): """Test rotation of real image with orientation value = 6""" # TODO: Bad test, should be removed or improved. image_path = os.path.join(this_dir, 'testfile_6.jpg') img = Image.open(image_path) assert img.width == 300 assert img.height == 225 assert img._getexif().get(274) == 6 img_rot = imdirect.autorotate(img) assert img_rot.width == 225 assert img_rot.height == 300 assert not hasattr(img_rot, '_getexif')
def handle(self, *args, **options): # not allowed in production if not settings.DEBUG: self.stdout.write(self.style.ERROR("DEBUG is off")) total = 0 rotated = 0 photos = Photo.objects.all() for photo in photos: print(settings.MEDIA_ROOT + photo.image.path) img = Image.open() print("{0}, Orientation: {1}".format(img, img._getexif().get(274))) img_rotated = imdirect.autorotate(img) total += 1 if total == 10: break message = 'Rotated %i of %i photos' % (rotated, total) self.stdout.write(self.style.SUCCESS(message))
def test_rotate_5(base_img, image_with_rotation_value_5): """Test rotation of image with orientation = 5""" rotated_img = imdirect.autorotate(image_with_rotation_value_5) x = list(rotated_img.getdata()) assert x == list(chain(*base_img))
from PIL import Image import imdirect img = Image.open('/home/caratred/Downloads/drivers/imageedit_2_3347203087.jpg') print(img) img_rotated = imdirect.autorotate(img)