Merge pull request #33 from axu2/master
Scale and Crop instead of Stretch
This commit is contained in:
commit
68c10024f9
@ -16,7 +16,7 @@
|
||||
|
||||
import os
|
||||
|
||||
from PIL import Image, ImageDraw, ImageStat, ImageChops
|
||||
from PIL import Image, ImageDraw, ImageStat, ImageChops, ImageOps
|
||||
|
||||
|
||||
class ImageFlags:
|
||||
@ -24,7 +24,7 @@ class ImageFlags:
|
||||
Resize = 1 << 1
|
||||
Frame = 1 << 2
|
||||
Quantize = 1 << 3
|
||||
Stretch = 1 << 4
|
||||
ScaleCrop = 1 << 4
|
||||
SplitRightLeft = 1 << 5 # split right then left
|
||||
SplitRight = 1 << 6 # split only the right page
|
||||
SplitLeft = 1 << 7 # split only the left page
|
||||
@ -134,10 +134,8 @@ def quantizeImage(image, palette):
|
||||
|
||||
|
||||
@protect_bad_image
|
||||
def stretchImage(image, size):
|
||||
widthDev, heightDev = size
|
||||
|
||||
return image.resize((widthDev, heightDev), Image.ANTIALIAS)
|
||||
def scaleCropImage(image, size):
|
||||
return ImageOps.fit(image, size, Image.ANTIALIAS)
|
||||
|
||||
|
||||
@protect_bad_image
|
||||
@ -277,8 +275,8 @@ def convertImage(source, target, device, flags):
|
||||
image = orientImage(image, size)
|
||||
if flags & ImageFlags.Resize:
|
||||
image = resizeImage(image, size)
|
||||
if flags & ImageFlags.Stretch:
|
||||
image = stretchImage(image, size)
|
||||
if flags & ImageFlags.ScaleCrop:
|
||||
image = scaleCropImage(image, size)
|
||||
if flags & ImageFlags.Frame:
|
||||
image = frameImage(image, tuple(palette[:3]), tuple(palette[-3:]), size)
|
||||
if flags & ImageFlags.Quantize:
|
||||
|
@ -43,7 +43,7 @@ class DialogOptions(QtGui.QDialog):
|
||||
self.checkboxOverwrite.setChecked(self.book.overwrite)
|
||||
self.checkboxOrient.setChecked(self.book.imageFlags & ImageFlags.Orient)
|
||||
self.checkboxResize.setChecked(self.book.imageFlags & ImageFlags.Resize)
|
||||
self.checkboxStretch.setChecked(self.book.imageFlags & ImageFlags.Stretch)
|
||||
self.checkboxScaleCrop.setChecked(self.book.imageFlags & ImageFlags.ScaleCrop)
|
||||
self.checkboxQuantize.setChecked(self.book.imageFlags & ImageFlags.Quantize)
|
||||
self.checkboxFrame.setChecked(self.book.imageFlags & ImageFlags.Frame)
|
||||
|
||||
@ -62,8 +62,8 @@ class DialogOptions(QtGui.QDialog):
|
||||
imageFlags |= ImageFlags.Orient
|
||||
if self.checkboxResize.isChecked():
|
||||
imageFlags |= ImageFlags.Resize
|
||||
if self.checkboxStretch.isChecked():
|
||||
imageFlags |= ImageFlags.Stretch
|
||||
if self.checkboxScaleCrop.isChecked():
|
||||
imageFlags |= ImageFlags.ScaleCrop
|
||||
if self.checkboxQuantize.isChecked():
|
||||
imageFlags |= ImageFlags.Quantize
|
||||
if self.checkboxFrame.isChecked():
|
||||
|
@ -215,9 +215,9 @@
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="checkboxStretch">
|
||||
<widget class="QRadioButton" name="checkboxScaleCrop">
|
||||
<property name="text">
|
||||
<string>Stretch images to fill the screen</string>
|
||||
<string>Scale and crop images to fill the screen</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
Loading…
Reference in New Issue
Block a user