# Path: mfr/core/extension.py
# class BaseExporter(metaclass=abc.ABCMeta):
# class BaseRenderer(metaclass=abc.ABCMeta):
#     def __init__(self, ext, source_file_path, output_file_path, format, metadata):
#     def export(self):
#     def _get_module_name(self):
#     def __init__(self, metadata, file_path, url, assets_url, export_url):
#     def render(self):
#     def file_required(self):
#     def cache_result(self):
#     def _get_module_name(self):
# 
# Path: mfr/extensions/image/settings.py
# EXPORT_BACKGROUND_COLOR = config.get('EXPORT_BACKGROUND_COLOR', 'white')


import os
import imghdr
import warnings
from PIL import Image
from psd_tools import PSDImage
from mfr.core import extension
from mfr.extensions.image import exceptions
from mfr.extensions.image.settings import EXPORT_BACKGROUND_COLOR
                # silence warnings from psd-tools
                # Warnings warn of outdated depedency that is a pain to install
                # and about colors being possibly wrong
                with warnings.catch_warnings():
                    warnings.simplefilter("ignore")
                    image = PSDImage.load(self.source_file_path).as_PIL()
            else:
                image = Image.open(self.source_file_path)

            # Only resize when both dimensions are available
            if max_size.get('w') and max_size.get('h'):
                # resize the image to the w/h maximum specified
                ratio = min(max_size['w'] / image.size[0], max_size['h'] / image.size[1])
                self.metrics.add('ratio', ratio)
                if ratio < 1:
                    size_tuple = (round(image.size[0] * ratio), round(image.size[1] * ratio))
                    image = image.resize(size_tuple, Image.ANTIALIAS)

            # Mode 'P' is for paletted images. They must be converted to RGB before exporting to
            # jpeg, otherwise Pillow will throw an error.  This is a temporary workaround, as the
            # conversion is imprecise and can be ugly.
            # See: https://stackoverflow.com/q/21669657
            if image.mode == 'P':
                image = image.convert('RGB')

            # handle transparency
            # from https://github.com/python-pillow/Pillow/issues/2609
            if image.mode in ('RGBA', 'RGBa', 'LA') and image_type in ['jpeg', 'jpg']:
                # JPEG has no transparency, so anything that was transparent gets changed to
                # EXPORT_BACKGROUND_COLOR. Default is white.

# Path: mfr/core/extension.py
# class BaseExporter(metaclass=abc.ABCMeta):
# class BaseRenderer(metaclass=abc.ABCMeta):
#     def __init__(self, ext, source_file_path, output_file_path, format, metadata):
#     def export(self):
#     def _get_module_name(self):
#     def __init__(self, metadata, file_path, url, assets_url, export_url):
#     def render(self):
#     def file_required(self):
#     def cache_result(self):
#     def _get_module_name(self):
# 
# Path: mfr/extensions/image/settings.py
# EXPORT_BACKGROUND_COLOR = config.get('EXPORT_BACKGROUND_COLOR', 'white')


# Path: mfr/extensions/image/export.py
import os
import imghdr
import warnings
from PIL import Image
from psd_tools import PSDImage
from mfr.core import extension
from mfr.extensions.image import exceptions
from mfr.extensions.image.settings import EXPORT_BACKGROUND_COLOR

                # silence warnings from psd-tools
                # Warnings warn of outdated depedency that is a pain to install
                # and about colors being possibly wrong
                with warnings.catch_warnings():
                    warnings.simplefilter("ignore")
                    image = PSDImage.load(self.source_file_path).as_PIL()
            else:
                image = Image.open(self.source_file_path)

            # Only resize when both dimensions are available
            if max_size.get('w') and max_size.get('h'):
                # resize the image to the w/h maximum specified
                ratio = min(max_size['w'] / image.size[0], max_size['h'] / image.size[1])
                self.metrics.add('ratio', ratio)
                if ratio < 1:
                    size_tuple = (round(image.size[0] * ratio), round(image.size[1] * ratio))
                    image = image.resize(size_tuple, Image.ANTIALIAS)

            # Mode 'P' is for paletted images. They must be converted to RGB before exporting to
            # jpeg, otherwise Pillow will throw an error.  This is a temporary workaround, as the
            # conversion is imprecise and can be ugly.
            # See: https://stackoverflow.com/q/21669657
            if image.mode == 'P':
                image = image.convert('RGB')

            # handle transparency
            # from https://github.com/python-pillow/Pillow/issues/2609
            if image.mode in ('RGBA', 'RGBa', 'LA') and image_type in ['jpeg', 'jpg']:
                # JPEG has no transparency, so anything that was transparent gets changed to
                # EXPORT_BACKGROUND_COLOR. Default is white.

                background = Image.new(image.mode[:-1], image.size, EXPORT_BACKGROUND_COLOR)