How to use the pyexiv2.ImageMetadata.from_buffer function in pyexiv2

To help you get started, we’ve selected a few pyexiv2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thumbor / thumbor / thumbor / engines / __init__.py View on Github external
self.extension = extension

        if extension is None:
            mime = self.get_mimetype(buffer)
            self.extension = EXTENSION.get(mime, '.jpg')

        if self.extension == '.svg':
            buffer = self.convert_svg_to_png(buffer)

        image_or_frames = self.create_image(buffer)
        if image_or_frames is None:
            return

        if METADATA_AVAILABLE:
            try:
                self.metadata = ImageMetadata.from_buffer(buffer)
                self.metadata.read()
            except Exception as e:
                logger.error('Error reading image metadata: %s' % e)

        if self.context.config.ALLOW_ANIMATED_GIFS and isinstance(
                image_or_frames, (list, tuple)):
            self.image = image_or_frames[0]
            if len(image_or_frames) > 1:
                self.multiple_engine = MultipleEngine(self)
                for frame in image_or_frames:
                    self.multiple_engine.add_frame(frame)
                self.wrap(self.multiple_engine)
        else:
            self.image = image_or_frames

        if self.source_width is None:
github spillz / picty / modules / picty / collectiontypes / flickr.py View on Github external
interrupt_fn=lambda:True
            from cStringIO import StringIO
            sio=StringIO()
            while interrupt_fn():
                s=fp.read(1024)
                if not s:
                    break
                sio.write(s)
                p.feed(s)
            item.image = p.close()
            if 'Orientation' in item.meta:
                orient_meta=item.meta
            else:
                try:
                    import pyexiv2
                    im=pyexiv2.ImageMetadata.from_buffer(sio.getvalue())
                    im.read()
                    orient_meta={'Orientation':im['Exif.Image.Orientation'].value}
                except:
                    orient_meta={}
            item.image=imagemanip.orient_image(item.image,orient_meta)
            if item.image:
                imagemanip.cache_image(item)
            return True
        except:
            print 'Failed to retrieve fullsize image for',item
            item.image=False
            import traceback,sys
            tb_text=traceback.format_exc(sys.exc_info()[2])
            print tb_text
            return False
github spillz / picty / modules / picty / collectiontypes / facebook.py View on Github external
interrupt_fn=lambda:True
            from cStringIO import StringIO
            sio=StringIO()
            while interrupt_fn():
                s=fp.read(1024)
                if not s:
                    break
                sio.write(s)
                p.feed(s)
            item.image = p.close()
            if 'Orientation' in item.meta:
                orient_meta=item.meta
            else:
                try:
                    import pyexiv2
                    im=pyexiv2.ImageMetadata.from_buffer(sio.getvalue())
                    im.read()
                    orient_meta={'Orientation':im['Exif.Image.Orientation'].value}
                except:
                    orient_meta={}
            item.image=imagemanip.orient_image(item.image,orient_meta)
            if item.image:
                imagemanip.cache_image(item)
            return True
        except:
            print 'Failed to retrieve fullsize image for',item
            item.image=False
            import traceback,sys
            tb_text=traceback.format_exc(sys.exc_info()[2])
            print tb_text
            return False