Пример #1
0
    def _crop(self, fieldname, scale, box):
        """Delegate to store.

        """
        storage = Storage(self.context)
        storage.store(fieldname, scale, box)

        if IImageCroppingDX.providedBy(self.context):
            return
        # AT BBB scaling.
        croputils = IImageCroppingUtils(self.context)
        data = croputils.get_image_data(fieldname)

        original_file = BytesIO(data)
        image = PIL.Image.open(original_file)
        image_format = image.format or self.DEFAULT_FORMAT

        cropped_image = image.crop(box)
        cropped_image_file = BytesIO()
        cropped_image.save(cropped_image_file, image_format, quality=100)
        cropped_image_file.seek(0)

        croputils.save_cropped(fieldname, scale, cropped_image_file)