-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix thumbnail geometry when DCT scaling is used #4231
Changes from 7 commits
2d1482b
4126f6c
375556f
fd21de7
e234445
c23f294
4e09215
a027897
b35cbef
b112e55
1275b10
532eca3
663fea3
c35fb6f
d991cd9
9c2b058
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1126,12 +1126,15 @@ def draft(self, mode, size): | |||||
""" | ||||||
Configures the image file loader so it returns a version of the | ||||||
image that as closely as possible matches the given mode and | ||||||
size. For example, you can use this method to convert a color | ||||||
size. For example, you can use this method to convert a color | ||||||
JPEG to greyscale while loading it, or to extract a 128x192 | ||||||
version from a PCD file. | ||||||
|
||||||
If any changes are made, returns a tuple with the chosen ``mode`` and | ||||||
``box`` with coordinates of the original image within the altered one. | ||||||
|
||||||
Note that this method modifies the :py:class:`~PIL.Image.Image` object | ||||||
in place. If the image has already been loaded, this method has no | ||||||
in place. If the image has already been loaded, this method has no | ||||||
effect. | ||||||
|
||||||
Note: This method is not implemented for most images. It is | ||||||
|
@@ -2143,14 +2146,17 @@ def thumbnail(self, size, resample=BICUBIC): | |||||
x = int(max(x * size[1] / y, 1)) | ||||||
y = int(size[1]) | ||||||
size = x, y | ||||||
box = None | ||||||
|
||||||
if size == self.size: | ||||||
return | ||||||
|
||||||
self.draft(None, size) | ||||||
res = self.draft(None, size) | ||||||
if res is not None: | ||||||
box = res[1] | ||||||
|
||||||
if self.size != size: | ||||||
im = self.resize(size, resample) | ||||||
im = self.resize(size, resample, box=box) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I suggest not specifying the argument name - it's not necessary, and the variable name already clearly indicates the purpose. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In truth, I think this is a case where we could use Keyword-Only Arguments. It seems obvious that we can omit the argument name when you watch on it and so you know that it exists and what exactly it is doing. But once you omit it, you can't know exactly where your variable goes. |
||||||
|
||||||
self.im = im.im | ||||||
self._size = size | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -409,7 +409,8 @@ def draft(self, mode, size): | |
return | ||
|
||
d, e, o, a = self.tile[0] | ||
scale = 0 | ||
scale = 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both values are not handled: https://github.com/python-pillow/Pillow/blob/master/src/libImaging/JpegDecode.c#L238 While 1 is more correct. |
||
original_size = self.size | ||
|
||
if a[0] == "RGB" and mode in ["L", "YCbCr"]: | ||
self.mode = mode | ||
|
@@ -432,7 +433,8 @@ def draft(self, mode, size): | |
self.tile = [(d, e, o, a)] | ||
self.decoderconfig = (scale, 0) | ||
|
||
return self | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is breaking change. Previously, I'll add this in docs. |
||
box = (0, 0, original_size[0] / float(scale), original_size[1] / float(scale)) | ||
return (self.mode, box) | ||
|
||
def load_djpeg(self): | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@radarhere Does this description look good for you?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created uploadcare#60 with my suggestion.