def test_get_image_metadata_when_there_is_none(self): with open(SOME_GIF, "r") as fh: contents = fh.read() metadata = ImageMetadata.image_metadata(contents) eq_(metadata, {})
def test_handles_oddly_malformed_metadata(self): with open(MALFORMED_JPG, "r") as fh: contents = fh.read() metadata = ImageMetadata.image_metadata(contents) eq_(metadata["aperture"], None)
def add(request_format): tag_names = request.form['tags'].split(' ') url = request.form['url'] if url: print 'fetching from remote url' truck = ImageTruck.new_from_url(url) elif request.files['file']: image = request.files['file'] truck = ImageTruck.new_from_stream(image.stream, image.mimetype) else: abort(400) metadata = ImageMetadata.image_metadata(truck.contents) print 'potentially reorienting' truck.contents = ReorientImage.reorient_image(truck.contents) print 'uploading to s3' truck.upload() session = Client().session() image = Image(filename=truck.calculate_filename(), source_url=url, description=request.form.get('description'), title=request.form.get('title'), **metadata) album_id = request.form['album'] if album_id: image.album_id = album_id session.add(image) image.add_tags(tag_names) ResizeImage.make_resizes(image, truck) if request_format == 'html': return redirect(url_for('show_image', image_id=image.image_id)) elif request_format == 'json': return {'url': truck.url()}
def process_image(self, image_contents_id): session = Client().session() contents = session.query(ImageContents).\ filter(ImageContents.image_contents_id == image_contents_id).\ one() image = session.query(Image).\ filter(Image.image_id == contents.image_id).\ one() truck = ImageTruck( contents.contents, contents.content_type, image.source_url) truck.filename = image.filename metadata = ImageMetadata.image_metadata(truck.contents) truck.contents = ReorientImage.reorient_image(truck.contents) def after_upload(size): redis.publish(REDIS_CHANNEL, json.dumps({ 'task_id': self.request.id, 'suffix': size, })) ResizeImage.make_resizes(image, truck, after_upload) print "uploading original image" truck.upload() redis.publish(REDIS_CHANNEL, json.dumps({ 'task_id': self.request.id, 'suffix': '', })) delay(queued_tasks, Invalidate(), image.image_id) for attr, value in metadata.iteritems(): setattr(image, attr, value) session.add(image) session.delete(contents)
def test_handles_oddly_malformed_metadata(self): test_file = os.path.join(os.path.dirname(__file__), 'test_image_malformed_exif.jpg') with open(test_file, 'r') as fh: contents = fh.read() metadata = ImageMetadata.image_metadata(contents) eq_(metadata['aperture'], None)
def test_get_image_metadata_when_there_is_none(self): test_file = os.path.join(os.path.dirname(__file__), 'test_image_500x319.gif') with open(test_file, 'r') as fh: contents = fh.read() metadata = ImageMetadata.image_metadata(contents) eq_(metadata, {})
def test_get_image_metadata(self): test_file = os.path.join(os.path.dirname(__file__), 'test_image_5472x3648.jpg') with open(test_file, 'r') as fh: contents = fh.read() metadata = ImageMetadata.image_metadata(contents) eq_(metadata, { 'camera': 'SAMSUNG NX210', 'photographed_at': '2013-05-03 09:17:02', 'aperture': '1/4.0', 'shutter_speed': '1/800', 'focal_length': 30, 'iso': 200, })
def test_get_image_metadata(self): with open(EXIF_JPG, "r") as fh: contents = fh.read() metadata = ImageMetadata.image_metadata(contents) eq_( metadata, { "camera": "SAMSUNG NX210", "photographed_at": "2013-05-03 09:17:02", "aperture": "1/4.5", "shutter_speed": "1/800", "focal_length": 30.0, "iso": 200, }, )
def test_calculate_shutter_speed(self): eq_(ImageMetadata._calculate_shutter_speed(1, 800), '1/800') eq_(ImageMetadata._calculate_shutter_speed(50, 10), '5')