mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
More fixes for PIL breaking its API
This commit is contained in:
parent
ed00de3b23
commit
3e5611da73
@ -263,7 +263,7 @@ class DunyaHalleri_HaftaninOzeti(BasicNewsRecipe):
|
|||||||
logo = Image.open(logo_file, 'r')
|
logo = Image.open(logo_file, 'r')
|
||||||
width, height = logo.size
|
width, height = logo.size
|
||||||
logo = logo.resize(
|
logo = logo.resize(
|
||||||
(self.COVER_WIDTH, (self.COVER_WIDTH * height / width)), Image.ANTIALIAS)
|
(self.COVER_WIDTH, (self.COVER_WIDTH * height / width)), Image.Resampling.LANCZOS)
|
||||||
width, height = logo.size
|
width, height = logo.size
|
||||||
left = max(int((self.COVER_WIDTH - width) / 2.), 0)
|
left = max(int((self.COVER_WIDTH - width) / 2.), 0)
|
||||||
top = max(int((self.COVER_HEIGHT - height) / 2.), 0)
|
top = max(int((self.COVER_HEIGHT - height) / 2.), 0)
|
||||||
|
@ -390,7 +390,7 @@ class WEBOS(USBMS):
|
|||||||
|
|
||||||
cover = Image.new('RGB', (120,160), 'black')
|
cover = Image.new('RGB', (120,160), 'black')
|
||||||
im = Image.open(io.BytesIO(coverdata))
|
im = Image.open(io.BytesIO(coverdata))
|
||||||
im.thumbnail((120, 160), Image.ANTIALIAS)
|
im.thumbnail((120, 160), Image.Resampling.LANCZOS)
|
||||||
|
|
||||||
x, y = im.size
|
x, y = im.size
|
||||||
cover.paste(im, ((120-x)/2, (160-y)/2))
|
cover.paste(im, ((120-x)/2, (160-y)/2))
|
||||||
@ -415,12 +415,12 @@ class WEBOS(USBMS):
|
|||||||
|
|
||||||
cover = Image.new('RGB', (52,69), 'black')
|
cover = Image.new('RGB', (52,69), 'black')
|
||||||
im = Image.open(io.BytesIO(coverdata))
|
im = Image.open(io.BytesIO(coverdata))
|
||||||
im.thumbnail((52, 69), Image.ANTIALIAS)
|
im.thumbnail((52, 69), Image.Resampling.LANCZOS)
|
||||||
|
|
||||||
x, y = im.size
|
x, y = im.size
|
||||||
cover.paste(im, ((52-x)//2, (69-y)//2))
|
cover.paste(im, ((52-x)//2, (69-y)//2))
|
||||||
|
|
||||||
cover2 = cover.resize((52, 69), Image.ANTIALIAS).convert('RGB')
|
cover2 = cover.resize((52, 69), Image.Resampling.LANCZOS).convert('RGB')
|
||||||
|
|
||||||
data = io.BytesIO()
|
data = io.BytesIO()
|
||||||
cover2.save(data, 'JPEG')
|
cover2.save(data, 'JPEG')
|
||||||
|
@ -34,7 +34,7 @@ def write_t2b(t2bfile, coverdata=None):
|
|||||||
if coverdata is not None:
|
if coverdata is not None:
|
||||||
coverdata = io.BytesIO(coverdata)
|
coverdata = io.BytesIO(coverdata)
|
||||||
cover = Image.open(coverdata).convert("L")
|
cover = Image.open(coverdata).convert("L")
|
||||||
cover.thumbnail((96, 144), Image.ANTIALIAS)
|
cover.thumbnail((96, 144), Image.Resampling.LANCZOS)
|
||||||
t2bcover = Image.new('L', (96, 144), 'white')
|
t2bcover = Image.new('L', (96, 144), 'white')
|
||||||
|
|
||||||
x, y = cover.size
|
x, y = cover.size
|
||||||
|
@ -22,7 +22,7 @@ def write_t4b(t4bfile, coverdata=None):
|
|||||||
if coverdata is not None:
|
if coverdata is not None:
|
||||||
coverdata = BytesIO(coverdata)
|
coverdata = BytesIO(coverdata)
|
||||||
cover = Image.open(coverdata).convert("L")
|
cover = Image.open(coverdata).convert("L")
|
||||||
cover.thumbnail((96, 144), Image.ANTIALIAS)
|
cover.thumbnail((96, 144), Image.Resampling.LANCZOS)
|
||||||
t4bcover = Image.new('L', (96, 144), 'white')
|
t4bcover = Image.new('L', (96, 144), 'white')
|
||||||
|
|
||||||
x, y = cover.size
|
x, y = cover.size
|
||||||
|
@ -57,7 +57,7 @@ class NOOK(USBMS):
|
|||||||
|
|
||||||
cover = Image.new('RGB', (96, 144), 'black')
|
cover = Image.new('RGB', (96, 144), 'black')
|
||||||
im = Image.open(io.BytesIO(coverdata))
|
im = Image.open(io.BytesIO(coverdata))
|
||||||
im.thumbnail((96, 144), Image.ANTIALIAS)
|
im.thumbnail((96, 144), Image.Resampling.LANCZOS)
|
||||||
|
|
||||||
x, y = im.size
|
x, y = im.size
|
||||||
cover.paste(im, ((96-x)/2, (144-y)/2))
|
cover.paste(im, ((96-x)/2, (144-y)/2))
|
||||||
|
@ -61,7 +61,7 @@ class PMLOutput(OutputFormatPlugin):
|
|||||||
im = Image.open(io.BytesIO(item.data))
|
im = Image.open(io.BytesIO(item.data))
|
||||||
else:
|
else:
|
||||||
im = Image.open(io.BytesIO(item.data)).convert('P')
|
im = Image.open(io.BytesIO(item.data)).convert('P')
|
||||||
im.thumbnail((300,300), Image.ANTIALIAS)
|
im.thumbnail((300,300), Image.Resampling.LANCZOS)
|
||||||
|
|
||||||
data = io.BytesIO()
|
data = io.BytesIO()
|
||||||
im.save(data, 'PNG')
|
im.save(data, 'PNG')
|
||||||
|
@ -939,7 +939,7 @@ class HTMLConverter:
|
|||||||
pt = PersistentTemporaryFile(suffix='_html2lrf_scaled_image_.'+encoding.lower())
|
pt = PersistentTemporaryFile(suffix='_html2lrf_scaled_image_.'+encoding.lower())
|
||||||
self.image_memory.append(pt) # Necessary, trust me ;-)
|
self.image_memory.append(pt) # Necessary, trust me ;-)
|
||||||
try:
|
try:
|
||||||
im.resize((int(width), int(height)), PILImage.ANTIALIAS).save(pt, encoding)
|
im.resize((int(width), int(height)), PILImage.Resampling.LANCZOS).save(pt, encoding)
|
||||||
pt.close()
|
pt.close()
|
||||||
self.scaled_images[path] = pt
|
self.scaled_images[path] = pt
|
||||||
return pt.name
|
return pt.name
|
||||||
|
@ -135,7 +135,7 @@ class Writer(FormatWriter):
|
|||||||
if item.media_type in OEB_RASTER_IMAGES and item.href in image_hrefs.keys():
|
if item.media_type in OEB_RASTER_IMAGES and item.href in image_hrefs.keys():
|
||||||
try:
|
try:
|
||||||
im = Image.open(io.BytesIO(item.data)).convert('P')
|
im = Image.open(io.BytesIO(item.data)).convert('P')
|
||||||
im.thumbnail((300,300), Image.ANTIALIAS)
|
im.thumbnail((300,300), Image.Resampling.LANCZOS)
|
||||||
|
|
||||||
data = io.BytesIO()
|
data = io.BytesIO()
|
||||||
im.save(data, 'PNG')
|
im.save(data, 'PNG')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user