예제 #1
0
class PGmagickTestCase(BaseCase):
    def __init__(self, *args, **kwargs):
        super(PGmagickTestCase, self).__init__(*args, **kwargs)
        self.engine = PGEngine()
        self.temp_dir = os.path.join(self.root_dir, "src", "temp")

    def setUp(self):
        # Above all, we need to create the temp folder, if not exists
        if not os.path.exists(self.temp_dir):
            os.mkdir(self.temp_dir)

    def get_comparable_image(self, options):
        """
        Creates a watermarked image with pgmagick engine and reopens it
        to return comparable PIL Image instance
        """
        bg = PGImage(self.bg_path)
        marked_image = self.engine.watermark(bg, options)
        path_kwargs = {
            "option_key": str(list(options.keys())[0]),
            "option_value": str(list(options.values())[0]),
        }
        temp_image_path = os.path.join(
            self.temp_dir, "{option_key}_{option_value}.png".format(**path_kwargs)
        )
        marked_image.write(temp_image_path)
        # https://github.com/python-pillow/Pillow/issues/835
        with open(temp_image_path, "rb") as image_file:
            with PILImage.open(image_file) as mark:
                os.remove(temp_image_path)
                return copy.deepcopy(mark)

    def tearDown(self):
        if os.path.exists(self.temp_dir):
            os.rmdir(self.temp_dir)
예제 #2
0
class PGmagickTestCase(unittest.TestCase, BaseCase):
    def setUp(self):
        self.engine = PGEngine()
        self.bg_path = 'src/bg.png'
        self.temp_dir = 'src/temp/'
        self.img_dir = 'src/control_instances/created_with_pil/png/'
        # Above all, we need to create the temp folder, if not exists
        if not os.path.exists(self.temp_dir):
            os.mkdir(self.temp_dir)

    def get_comparable_image(self, options):
        """
        Creates a watermarked image with pgmagick engine and reopens it
        to return comparable PIL Image instance
        """
        bg = PGImage(self.bg_path)
        marked_image = self.engine.watermark(bg, options)
        temp_image_path = self.temp_dir + str(options.keys()[0]) + \
                          "_" + str(options.values()[0]) + '.png'
        marked_image.write(temp_image_path)
        mark = PILImage.open(temp_image_path)
        os.remove(temp_image_path)
        return mark

    def tearDown(self):
        if os.path.exists(self.temp_dir):
            os.rmdir(self.temp_dir)
예제 #3
0
class PGmagickTestCase(unittest.TestCase, BaseCase):
    def setUp(self):
        self.engine = PGEngine()
        self.bg_path = "src/bg.png"
        self.temp_dir = "src/temp/"
        self.img_dir = "src/control_instances/created_with_pil/png/"
        # Above all, we need to create the temp folder, if not exists
        if not os.path.exists(self.temp_dir):
            os.mkdir(self.temp_dir)

    def get_comparable_image(self, options):
        """
        Creates a watermarked image with pgmagick engine and reopens it
        to return comparable PIL Image instance
        """
        bg = PGImage(self.bg_path)
        marked_image = self.engine.watermark(bg, options)
        temp_image_path = self.temp_dir + str(options.keys()[0]) + "_" + str(options.values()[0]) + ".png"
        marked_image.write(temp_image_path)
        mark = PILImage.open(temp_image_path)
        os.remove(temp_image_path)
        return mark

    def tearDown(self):
        if os.path.exists(self.temp_dir):
            os.rmdir(self.temp_dir)
예제 #4
0
 def setUp(self):
     self.engine = PGEngine()
     self.bg_path = 'src/bg.png'
     self.temp_dir = 'src/temp/'
     self.img_dir = 'src/control_instances/created_with_pil/png/'
     # Above all, we need to create the temp folder, if not exists
     if not os.path.exists(self.temp_dir):
         os.mkdir(self.temp_dir)
예제 #5
0
 def setUp(self):
     self.engine = PGEngine()
     self.bg_path = "src/bg.png"
     self.temp_dir = "src/temp/"
     self.img_dir = "src/control_instances/created_with_pil/png/"
     # Above all, we need to create the temp folder, if not exists
     if not os.path.exists(self.temp_dir):
         os.mkdir(self.temp_dir)
예제 #6
0
 def __init__(self, *args, **kwargs):
     super(PGmagickTestCase, self).__init__(*args, **kwargs)
     self.engine = PGEngine()
     self.temp_dir = os.path.join(self.root_dir, "src", "temp")