mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add crop_image()
This commit is contained in:
parent
bd822c7ff2
commit
0fbcabad73
@ -146,6 +146,20 @@ def scale_image(data, width=60, height=80, compression_quality=70, as_png=False,
|
|||||||
w, h = img.width(), img.height()
|
w, h = img.width(), img.height()
|
||||||
return w, h, image_to_data(img, compression_quality=compression_quality, fmt=fmt)
|
return w, h, image_to_data(img, compression_quality=compression_quality, fmt=fmt)
|
||||||
|
|
||||||
|
def crop_image(img, x, y, width, height):
|
||||||
|
'''
|
||||||
|
Return the specified section of the image.
|
||||||
|
|
||||||
|
:param x, y: The top left corner of the crop box
|
||||||
|
:param width, height: The width and height of the crop box. Note that if
|
||||||
|
the crop box exceeds the source images dimensions, width and height will be
|
||||||
|
auto-truncated.
|
||||||
|
'''
|
||||||
|
img = image_from_data(img)
|
||||||
|
width = min(width, img.width() - x)
|
||||||
|
height = min(height, img.height() - y)
|
||||||
|
return img.copy(x, y, width, height)
|
||||||
|
|
||||||
def normalize_format_name(fmt):
|
def normalize_format_name(fmt):
|
||||||
fmt = fmt.lower()
|
fmt = fmt.lower()
|
||||||
if fmt == 'jpg':
|
if fmt == 'jpg':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user