Compare commits
11 Commits
0d11e6ae5a
...
2d710ee74e
Author | SHA1 | Date | |
---|---|---|---|
|
2d710ee74e | ||
|
5a5188ee52 | ||
2c8a539f39 | |||
|
70656272d1 | ||
|
383cf86076 | ||
|
0dbc45fc41 | ||
|
cebfde3174 | ||
|
aeb813f76b | ||
|
7df96e86eb | ||
|
b70da17f80 | ||
|
08a3f4f075 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -145,6 +145,9 @@ cython_debug/
|
|||||||
*.cbz
|
*.cbz
|
||||||
*.pdf
|
*.pdf
|
||||||
|
|
||||||
|
# vscode
|
||||||
|
.vscode/
|
||||||
|
|
||||||
*.bat
|
*.bat
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
|
@ -1,12 +1,3 @@
|
|||||||
<!-- +++
|
|
||||||
Area = "projects"
|
|
||||||
GitHub = "mangle"
|
|
||||||
Layout = "page"
|
|
||||||
Tags = ["kindle", "manga", "mangle", "pil", "pyqt", "python", "gpl license"]
|
|
||||||
Description = "Manga processor for the Kindle e-book reader."
|
|
||||||
Collection = "ProjectsComplete"
|
|
||||||
+++ -->
|
|
||||||
|
|
||||||
# Mangle
|
# Mangle
|
||||||
|
|
||||||
Mangle is a cross-platform image converter and optimizer built for reading Manga on the Amazon Kindle and other E-ink
|
Mangle is a cross-platform image converter and optimizer built for reading Manga on the Amazon Kindle and other E-ink
|
||||||
|
@ -24,12 +24,14 @@ class ImageFlags:
|
|||||||
Resize = 1 << 1
|
Resize = 1 << 1
|
||||||
Frame = 1 << 2
|
Frame = 1 << 2
|
||||||
Quantize = 1 << 3
|
Quantize = 1 << 3
|
||||||
ScaleCrop = 1 << 4
|
Fit = 1 << 4
|
||||||
SplitRightLeft = 1 << 5 # split right then left
|
SplitRightLeft = 1 << 5 # split right then left
|
||||||
SplitRight = 1 << 6 # split only the right page
|
SplitRight = 1 << 6 # split only the right page
|
||||||
SplitLeft = 1 << 7 # split only the left page
|
SplitLeft = 1 << 7 # split only the left page
|
||||||
SplitLeftRight = 1 << 8 # split left then right page
|
SplitLeftRight = 1 << 8 # split left then right page
|
||||||
AutoCrop = 1 << 9
|
AutoCrop = 1 << 9
|
||||||
|
Fill = 1 << 10
|
||||||
|
Stretch = 1 << 11
|
||||||
|
|
||||||
|
|
||||||
class KindleData:
|
class KindleData:
|
||||||
@ -134,17 +136,45 @@ def quantizeImage(image, palette):
|
|||||||
|
|
||||||
|
|
||||||
@protect_bad_image
|
@protect_bad_image
|
||||||
def scaleCropImage(image, size):
|
def fitImage(image, size, method=Image.ANTIALIAS):
|
||||||
|
# copied from ImageOps.contain() from the Python3 version of Pillow
|
||||||
|
# with division related modifications for Python2
|
||||||
|
|
||||||
|
im_ratio = 1.0 * image.width / image.height
|
||||||
|
dest_ratio = 1.0 * size[0] / size[1]
|
||||||
|
|
||||||
|
if im_ratio != dest_ratio:
|
||||||
|
if im_ratio > dest_ratio:
|
||||||
|
new_height = int(1.0 * image.height / image.width * size[0])
|
||||||
|
if new_height != size[1]:
|
||||||
|
size = (size[0], new_height)
|
||||||
|
else:
|
||||||
|
new_width = int(1.0 * image.width / image.height * size[1])
|
||||||
|
if new_width != size[0]:
|
||||||
|
size = (new_width, size[1])
|
||||||
|
return image.resize(size, resample=method)
|
||||||
|
|
||||||
|
|
||||||
|
@protect_bad_image
|
||||||
|
def fillImage(image, size):
|
||||||
widthDev, heightDev = size
|
widthDev, heightDev = size
|
||||||
widthImg, heightImg = image.size
|
widthImg, heightImg = image.size
|
||||||
|
|
||||||
|
imgRatio = float(widthImg) / float(heightImg)
|
||||||
|
devRatio = float(widthDev) / float(heightDev)
|
||||||
|
|
||||||
# don't crop 2 page spreads.
|
# don't crop 2 page spreads.
|
||||||
if (float(widthImg) / float(heightImg)) > (float(widthDev) / float(heightDev)):
|
if imgRatio > devRatio:
|
||||||
return resizeImage(image, size)
|
return resizeImage(image, size)
|
||||||
|
|
||||||
return ImageOps.fit(image, size, Image.ANTIALIAS)
|
return ImageOps.fit(image, size, Image.ANTIALIAS)
|
||||||
|
|
||||||
|
|
||||||
|
@protect_bad_image
|
||||||
|
def stretchImage(image, size):
|
||||||
|
return image.resize(size, Image.ANTIALIAS)
|
||||||
|
|
||||||
|
|
||||||
@protect_bad_image
|
@protect_bad_image
|
||||||
def resizeImage(image, size):
|
def resizeImage(image, size):
|
||||||
widthDev, heightDev = size
|
widthDev, heightDev = size
|
||||||
@ -182,8 +212,11 @@ def orientImage(image, size):
|
|||||||
widthDev, heightDev = size
|
widthDev, heightDev = size
|
||||||
widthImg, heightImg = image.size
|
widthImg, heightImg = image.size
|
||||||
|
|
||||||
|
if widthImg <= widthDev and heightImg <= heightDev:
|
||||||
|
return image
|
||||||
|
|
||||||
if (widthImg > heightImg) != (widthDev > heightDev):
|
if (widthImg > heightImg) != (widthDev > heightDev):
|
||||||
return image.rotate(90, Image.BICUBIC, True)
|
return image.transpose(Image.ROTATE_90)
|
||||||
return image
|
return image
|
||||||
|
|
||||||
|
|
||||||
@ -191,12 +224,11 @@ def orientImage(image, size):
|
|||||||
# by inverting colors, and asking a bounder box ^^
|
# by inverting colors, and asking a bounder box ^^
|
||||||
@protect_bad_image
|
@protect_bad_image
|
||||||
def autoCropImage(image):
|
def autoCropImage(image):
|
||||||
w, h = image.size
|
|
||||||
try:
|
try:
|
||||||
x0, y0, xend, yend = ImageChops.invert(image).getbbox()
|
x0, y0, xend, yend = ImageChops.invert(image).getbbox()
|
||||||
except TypeError: # bad image, specific to chops
|
except TypeError: # bad image, specific to chops
|
||||||
return image
|
return image
|
||||||
image = image.crop((0, y0, w, yend))
|
image = image.crop((x0, y0, xend, yend))
|
||||||
|
|
||||||
return image
|
return image
|
||||||
|
|
||||||
@ -283,8 +315,12 @@ def convertImage(source, target, device, flags):
|
|||||||
image = orientImage(image, size)
|
image = orientImage(image, size)
|
||||||
if flags & ImageFlags.Resize:
|
if flags & ImageFlags.Resize:
|
||||||
image = resizeImage(image, size)
|
image = resizeImage(image, size)
|
||||||
if flags & ImageFlags.ScaleCrop:
|
if flags & ImageFlags.Fit:
|
||||||
image = scaleCropImage(image, size)
|
image = fitImage(image, size)
|
||||||
|
if flags & ImageFlags.Fill:
|
||||||
|
image = fillImage(image, size)
|
||||||
|
if flags & ImageFlags.Stretch:
|
||||||
|
image = stretchImage(image, size)
|
||||||
if flags & ImageFlags.Frame:
|
if flags & ImageFlags.Frame:
|
||||||
image = frameImage(image, tuple(palette[:3]), tuple(palette[-3:]), size)
|
image = frameImage(image, tuple(palette[:3]), tuple(palette[-3:]), size)
|
||||||
if flags & ImageFlags.Quantize:
|
if flags & ImageFlags.Quantize:
|
||||||
|
@ -43,7 +43,9 @@ class DialogOptions(QtGui.QDialog):
|
|||||||
self.checkboxOverwrite.setChecked(self.book.overwrite)
|
self.checkboxOverwrite.setChecked(self.book.overwrite)
|
||||||
self.checkboxOrient.setChecked(self.book.imageFlags & ImageFlags.Orient)
|
self.checkboxOrient.setChecked(self.book.imageFlags & ImageFlags.Orient)
|
||||||
self.checkboxResize.setChecked(self.book.imageFlags & ImageFlags.Resize)
|
self.checkboxResize.setChecked(self.book.imageFlags & ImageFlags.Resize)
|
||||||
self.checkboxScaleCrop.setChecked(self.book.imageFlags & ImageFlags.ScaleCrop)
|
self.checkboxFit.setChecked(self.book.imageFlags & ImageFlags.Fit)
|
||||||
|
self.checkboxFill.setChecked(self.book.imageFlags & ImageFlags.Fill)
|
||||||
|
self.checkboxStretch.setChecked(self.book.imageFlags & ImageFlags.Stretch)
|
||||||
self.checkboxQuantize.setChecked(self.book.imageFlags & ImageFlags.Quantize)
|
self.checkboxQuantize.setChecked(self.book.imageFlags & ImageFlags.Quantize)
|
||||||
self.checkboxFrame.setChecked(self.book.imageFlags & ImageFlags.Frame)
|
self.checkboxFrame.setChecked(self.book.imageFlags & ImageFlags.Frame)
|
||||||
|
|
||||||
@ -62,8 +64,12 @@ class DialogOptions(QtGui.QDialog):
|
|||||||
imageFlags |= ImageFlags.Orient
|
imageFlags |= ImageFlags.Orient
|
||||||
if self.checkboxResize.isChecked():
|
if self.checkboxResize.isChecked():
|
||||||
imageFlags |= ImageFlags.Resize
|
imageFlags |= ImageFlags.Resize
|
||||||
if self.checkboxScaleCrop.isChecked():
|
if self.checkboxFit.isChecked():
|
||||||
imageFlags |= ImageFlags.ScaleCrop
|
imageFlags |= ImageFlags.Fit
|
||||||
|
if self.checkboxFill.isChecked():
|
||||||
|
imageFlags |= ImageFlags.Fill
|
||||||
|
if self.checkboxStretch.isChecked():
|
||||||
|
imageFlags |= ImageFlags.Stretch
|
||||||
if self.checkboxQuantize.isChecked():
|
if self.checkboxQuantize.isChecked():
|
||||||
imageFlags |= ImageFlags.Quantize
|
imageFlags |= ImageFlags.Quantize
|
||||||
if self.checkboxFrame.isChecked():
|
if self.checkboxFrame.isChecked():
|
||||||
|
@ -215,9 +215,23 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QRadioButton" name="checkboxScaleCrop">
|
<widget class="QRadioButton" name="checkboxFit">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Scale and crop images to fill screen width</string>
|
<string>Fit to screen with borders</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="checkboxFill">
|
||||||
|
<property name="text">
|
||||||
|
<string>Fill screen by cropping</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QRadioButton" name="checkboxStretch">
|
||||||
|
<property name="text">
|
||||||
|
<string>Stretch images to fill screen</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
Loading…
Reference in New Issue
Block a user