def test_avatar_image(self, user, channel_factory, banner_img_file): channel = channel_factory(avatar_image=banner_img_file, user=user) assert channel.avatar_image # Check all exif data was removed exif_image = ExifImage(channel.avatar_image) assert exif_image.list_all() == []
def test_remove_exif_data(uploaded_img_with_exif): img_file_obj, _ = uploaded_img_with_exif result_file_obj = images.remove_exif_data(img_file_obj) # Check all exif data was removed exif_image = ExifImage(result_file_obj) assert exif_image.list_all() == []
def test_video_custom_thumbnail_image(video_factory, uploaded_img_with_exif): img_file_obj, _ = uploaded_img_with_exif video = video_factory(custom_thumbnail_image=img_file_obj) assert video.custom_thumbnail_image # Check all exif data was removed exif_image = ExifImage(video.custom_thumbnail_image) assert exif_image.list_all() == []
def uploaded_img_with_exif(): """An image with some EXIF data including GPS.""" img_path = EXAMPLE_IMG_EXIF_GPS with img_path.open('rb') as file_: file_contents = file_.read() file_.seek(0) exif_image = ExifImage(file_) assert exif_image.has_exif assert exif_image.list_all() return ( SimpleUploadedFile(img_path.name, file_contents), img_path, )
def photo_upload(): if request.method == 'GET': return photo_upload_page() category = request.values.get('category') or request.values.get( 'category_new') date = datetime.strptime(request.values.get('date'), '%Y-%m-%d') photos = request.files.getlist('photo') description = request.values.get('description') if not category or not date or not photos: errors = {'category': category, 'date': date, 'photo': photos} return photo_upload_page( errors=[k for k, v in errors.items() if not v]) for photo in photos: try: exif = ExifImage(photo.stream) if exif.has_exif: date_str = exif.get('datetime_original') or exif.get( 'datetime') if date_str: photo_date = datetime.strptime(date_str, '%Y:%m:%d %H:%M:%S') else: photo_date = date except: photo_date = date photo.stream.seek(0) extension = get_extension(photo.filename) filename = f'{random.key(16)}.{extension}' photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) thumbnail(os.path.join(app.config['UPLOAD_FOLDER'], filename)) db.session.add( Photo(creator_id=current_user.id, category=category, description=description, filename=filename, creation_date=photo_date)) # Commit per photo in case upload fails halfway db.session.commit() return redirect(url_for('show_albums'))
def get_exif(image, row): with open(image['file'], 'rb') as image_file: my_image = ExifImage(image_file) if my_image.has_exif: for tag in EXIF_TAGS: row[tag] = my_image.get(tag)
transformation_funcs = { 1: lambda img: img.rotate(180, resample=Image.BICUBIC, expand=True), # used only if rotate-only-orientation-1-by-180 is True 6: lambda img: img.rotate(-90, resample=Image.BICUBIC, expand=True), 8: lambda img: img.rotate(90, resample=Image.BICUBIC, expand=True), 3: lambda img: img.rotate(180, resample=Image.BICUBIC, expand=True), 2: lambda img: img.transpose(Image.FLIP_LEFT_RIGHT), 5: lambda img: img.rotate(-90, resample=Image.BICUBIC, expand=True).transpose(Image.FLIP_LEFT_RIGHT), 7: lambda img: img.rotate(90, resample=Image.BICUBIC, expand=True).transpose(Image.FLIP_LEFT_RIGHT), 4: lambda img: img.rotate(180, resample=Image.BICUBIC, expand=True).transpose(Image.FLIP_LEFT_RIGHT), } for img_path in glob(os.path.join(args.dir, '*.jpg')): print(img_path) with open(img_path, 'rb') as image_file: my_image = ExifImage(image_file) try: orientation = my_image.orientation.value except: print(' N/A skipping') continue if orientation == 1: if not args.rotate_only_orientation_1_by_180: print(' 1 skipping') continue else: print(' ', orientation, 'transforming (180° rotation)') else: if not args.rotate_only_orientation_1_by_180: print(' ', orientation, 'transforming') else:
def extract_exif(filepath): with open(filepath, 'rb') as file: exif = ExifImage(file) return exif