Ejemplo n.º 1
0
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)
Ejemplo n.º 3
0
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')
Ejemplo n.º 4
0
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))
Ejemplo n.º 6
0
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))
Ejemplo n.º 7
0
from PIL import Image
import imdirect
img = Image.open('/home/caratred/Downloads/drivers/imageedit_2_3347203087.jpg')
print(img)
img_rotated = imdirect.autorotate(img)