コード例 #1
0
 def crop(self, image, geometry, options):
     """
     Wrapper for ``_crop``
     """
     crop = options['crop']
     if not crop or crop == 'noop':
         return image
     x_image, y_image = self.get_image_size(image)
     x_offset, y_offset = parse_crop(crop, (x_image, y_image), geometry)
     return self._crop(image, geometry[0], geometry[1], x_offset, y_offset)
コード例 #2
0
ファイル: models.py プロジェクト: powderflask/cms-thumbnail
def deserialize_options(option_string):
    """ 
       Split out options from option_string and return them as a dict 
       Raise ThumbnailParseError if any syntax errors are discovered.
    """
    options = {}
    bits = iter(smart_split(option_string))
    for bit in bits:
        m = kw_pat.match(bit)
        if not m:
            raise ThumbnailParseError("Invalid thumbnail option: %s" % bit)
        key = smart_str(m.group("key"))
        value = smart_str(m.group("value")).strip("\"'")

        # if the key is "crop" then validate the crop options - raises ThumbnailParseError is invalid
        if key == "crop":
            parse_crop(value, [0, 0], [0, 0])

        options[key] = value
    return options
コード例 #3
0
ファイル: base.py プロジェクト: sethdenner/sorl-thumbnail
    def crop(self, image, options):
        """
        Wrapper for ``_crop``
        """
        crop = options['crop']
        if not crop or crop == 'noop':
            return image

        x_image, y_image = self.get_image_size(image)
        left, top, width, height = parse_crop(crop, (x_image, y_image))
        if left + width > x_image or top + height > y_image:
            return image
        return self._crop(image, width, height, left, top)
コード例 #4
0
ファイル: base.py プロジェクト: b-dev/sorl-thumbnail
 def crop(self, image, geometry, options):
     """
     Wrapper for ``_crop``
     """
     crop = options['crop']
     if not crop or crop == 'noop':
         return image
     # Smart cropping is suitably different from regular cropping
     # to warrent it's own function
     image_size = self.get_image_size(image)
     if crop == 'smart':
         import logging
         logging.warn('smart')
         return self._entropy_crop(image, geometry[0], geometry[1], image_size[0], image_size[1])
     x_offset, y_offset = parse_crop(crop, image_size, geometry)
     return self._crop(image, geometry[0], geometry[1], x_offset, y_offset)
コード例 #5
0
ファイル: base.py プロジェクト: radiosilence/sorl-thumbnail
    def crop(self, image, geometry, options):
        """
        Wrapper for ``_crop``
        """
        crop = options['crop']
        upscale = options['upscale']
        x_image, y_image = self.get_image_size(image)
        factor = self._calculate_scaling_factor(x_image, y_image, geometry, options)

        if not crop or crop == 'noop' or (not upscale and factor >= 1):
            return image

        geometry = (min(x_image, geometry[0]), min(y_image, geometry[1]))
        x_offset, y_offset = parse_crop(crop, (x_image, y_image), geometry)

        return self._crop(image, geometry[0], geometry[1], x_offset, y_offset)
コード例 #6
0
    def crop(self, image, geometry, options):
        """
        Wrapper for ``_crop``
        """
        crop = options['crop']
        upscale = options['upscale']
        x_image, y_image = self.get_image_size(image)
        factor = self._calculate_scaling_factor(x_image, y_image, geometry,
                                                options)

        if not crop or crop == 'noop' or (not upscale and factor >= 1):
            return image

        geometry = (min(x_image, geometry[0]), min(y_image, geometry[1]))
        x_offset, y_offset = parse_crop(crop, (x_image, y_image), geometry)

        return self._crop(image, geometry[0], geometry[1], x_offset, y_offset)
コード例 #7
0
ファイル: base.py プロジェクト: bihicheng/sorl-thumbnail
    def crop(self, image, geometry, options):
        """
        Wrapper for ``_crop``
        """
        crop = options['crop']
        x_image, y_image = self.get_image_size(image)

        if not crop or crop == 'noop':
            return image
        elif crop == 'smart':
            # Smart cropping is suitably different from regular cropping
            # to warrent it's own function
            return self._entropy_crop(image, geometry[0], geometry[1], x_image, y_image)

        # Handle any other crop option with the backend crop function.
        geometry = (min(x_image, geometry[0]), min(y_image, geometry[1]))
        x_offset, y_offset = parse_crop(crop, (x_image, y_image), geometry)
        return self._crop(image, geometry[0], geometry[1], x_offset, y_offset)
コード例 #8
0
ファイル: 25843_base.py プロジェクト: Sudeep20/bookshare
    def crop(self, image, geometry, options):
        """
        Wrapper for ``_crop``
        """
        crop = options['crop']
        x_image, y_image = self.get_image_size(image)

        if not crop or crop == 'noop':
            return image
        elif crop == 'smart':
            # Smart cropping is suitably different from regular cropping
            # to warrent it's own function
            return self._entropy_crop(image, geometry[0], geometry[1], x_image, y_image)

        # Handle any other crop option with the backend crop function.
        geometry = (min(x_image, geometry[0]), min(y_image, geometry[1]))
        x_offset, y_offset = parse_crop(crop, (x_image, y_image), geometry)
        return self._crop(image, geometry[0], geometry[1], x_offset, y_offset)
コード例 #9
0
ファイル: tests.py プロジェクト: jaivikram/sorl-thumbnail
 def test_px_crop(self):
     crop = parse_crop('200px 33px', (500, 500), (400, 400))
     self.assertEqual(crop, (100, 33))
コード例 #10
0
ファイル: tests.py プロジェクト: jaivikram/sorl-thumbnail
 def test_percent_crop(self):
     crop = parse_crop('50% 0%', (500, 500), (400, 400))
     self.assertEqual(crop, (50, 0))
     crop = parse_crop('10% 80%', (500, 500), (400, 400))
     self.assertEqual(crop, (10, 80))
コード例 #11
0
ファイル: tests.py プロジェクト: jaivikram/sorl-thumbnail
 def test_alias_crop(self):
     crop = parse_crop('center', (500, 500), (400, 400))
     self.assertEqual(crop, (50, 50))
     crop = parse_crop('right', (500, 500), (400, 400))
     self.assertEqual(crop, (100, 50))
コード例 #12
0
ファイル: tests.py プロジェクト: aalebedev/sorl-thumbnail
 def test_px_crop(self):
     crop = parse_crop('200px 33px', (500, 500), (400, 400))
     self.assertEqual(crop, (100, 33))
コード例 #13
0
ファイル: tests.py プロジェクト: aalebedev/sorl-thumbnail
 def test_percent_crop(self):
     crop = parse_crop('50% 0%', (500, 500), (400, 400))
     self.assertEqual(crop, (50, 0))
     crop = parse_crop('10% 80%', (500, 500), (400, 400))
     self.assertEqual(crop, (10, 80))
コード例 #14
0
ファイル: tests.py プロジェクト: hvdklauw/sorl-thumbnail
 def testPercentCrop(self):
     crop = parse_crop("50% 0%", (500, 500), (400, 400))
     self.assertEqual(crop, (50, 0))
     crop = parse_crop("10% 80%", (500, 500), (400, 400))
     self.assertEqual(crop, (10, 80))
コード例 #15
0
ファイル: tests.py プロジェクト: hvdklauw/sorl-thumbnail
 def testPxCrop(self):
     crop = parse_crop("200px 33px", (500, 500), (400, 400))
     self.assertEqual(crop, (100, 33))
コード例 #16
0
ファイル: tests.py プロジェクト: aalebedev/sorl-thumbnail
 def test_alias_crop(self):
     crop = parse_crop('center', (500, 500), (400, 400))
     self.assertEqual(crop, (50, 50))
     crop = parse_crop('right', (500, 500), (400, 400))
     self.assertEqual(crop, (100, 50))
コード例 #17
0
ファイル: tests.py プロジェクト: hvdklauw/sorl-thumbnail
 def testAliasCrop(self):
     crop = parse_crop("center", (500, 500), (400, 400))
     self.assertEqual(crop, (50, 50))
     crop = parse_crop("right", (500, 500), (400, 400))
     self.assertEqual(crop, (100, 50))