API to rotate images

This commit is contained in:
Kovid Goyal 2016-05-07 08:39:22 +05:30
parent b0844e0502
commit 019eaad9d7

View File

@ -7,7 +7,7 @@ from __future__ import (unicode_literals, division, absolute_import,
import os, subprocess, errno, shutil, tempfile
from threading import Thread
from PyQt5.Qt import QImage, QByteArray, QBuffer, Qt, QImageReader, QColor, QImageWriter
from PyQt5.Qt import QImage, QByteArray, QBuffer, Qt, QImageReader, QColor, QImageWriter, QTransform
from calibre import fit_image, force_unicode
from calibre.constants import iswindows, plugins
@ -238,6 +238,11 @@ class Canvas(object):
def flip_image(img, horizontal=False, vertical=False):
return image_from_data(img).mirrored(horizontal, vertical)
def rotate_image(img, degrees):
t = QTransform()
t.rotate(degrees)
return image_from_data(img).transformed(t)
def remove_borders(img, fuzz=None):
''' Try to auto-detect and remove any borders from the image. Returns
the image itself if no borders could be removed. `fuzz` is a measure of