Add back smart cropping #110

Merged
merged 2 commits into from Mar 23, 2014

2 participants

@hcliff

Add back smart cropping, it crops to the correct aspect ratio from where scale takes over.

Also introduced the remove_border flag, which will remove very low entropy data before the scale:

get_thumbnail(object.Image, '160x160', crop='smart', remove_border=True)

@hcliff

Worth noting that this is PIL only and requires python 2.7

@mariocesar
Owner

@hcliff can you review your pull request again, I will like to merge this into master

@hcliff

I'll need some time, it's been a while since I've touched this code

@mariocesar
Owner

I appreciate it, and please add you in the AUTHORS list when you finish

@mariocesar mariocesar commented on the diff Mar 23, 2014
sorl/thumbnail/engines/base.py
@@ -32,6 +33,14 @@ def colorspace(self, image, geometry, options):
"""
colorspace = options['colorspace']
return self._colorspace(image, colorspace)
+
+ def remove_border(self, image, options):
+
+ if options.get('remove_border', False):
@mariocesar
Owner
mariocesar added a line comment Mar 23, 2014

This is correct? is not "If remeve border is True?"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mariocesar mariocesar commented on the diff Mar 23, 2014
sorl/thumbnail/engines/base.py
@@ -119,6 +132,19 @@ def _colorspace(self, image, colorspace):
RGB, GRAY
"""
raise NotImplemented()
+
+ def _remove_border(self, image):
+ """
+ Remove borders around images
+ """
+ raise NotImplemented()
+
+ def _entropy_crop(self, image, image_ratio, geometry_ratio):
@mariocesar
Owner
mariocesar added a line comment Mar 23, 2014

The correct arguments are:

def _entropy_crop(self, image, geometry_width, geometry_height, image_width, image_height):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mariocesar mariocesar commented on the diff Mar 23, 2014
sorl/thumbnail/engines/base.py
@@ -119,6 +132,19 @@ def _colorspace(self, image, colorspace):
RGB, GRAY
"""
raise NotImplemented()
+
+ def _remove_border(self, image):
@mariocesar
Owner
mariocesar added a line comment Mar 23, 2014

The correct arguments will be:

  def _remove_border(self, image, image_width, image_height):
        """
        Remove borders around images
        """
        raise NotImplemented()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@mariocesar mariocesar merged commit 869c014 into mariocesar:master Mar 23, 2014
@mariocesar
Owner

I merge this, it needs tests. I added a issue about that #250

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment