diff --git a/src/calibre/gui2/tweak_book/editor/canvas.py b/src/calibre/gui2/tweak_book/editor/canvas.py index 39126e7e92..e71ffc3783 100644 --- a/src/calibre/gui2/tweak_book/editor/canvas.py +++ b/src/calibre/gui2/tweak_book/editor/canvas.py @@ -21,7 +21,10 @@ from calibre.gui2.dnd import ( IMAGE_EXTENSIONS, dnd_has_extension, dnd_has_image, dnd_get_image, DownloadDialog) from calibre.gui2.tweak_book import capitalize from calibre.utils.imghdr import identify -from calibre.utils.img import remove_borders, gaussian_sharpen, gaussian_blur, image_to_data, despeckle, normalize +from calibre.utils.img import ( + remove_borders, gaussian_sharpen, gaussian_blur, image_to_data, despeckle, + normalize, oil_paint +) def painter(func): @wraps(func) @@ -142,6 +145,17 @@ class Blur(Sharpen): def __call__(self, canvas): return gaussian_blur(canvas.current_image, sigma=self.sigma) +class Oilify(Command): + + TEXT = _('Make image look like an oil painting') + + def __init__(self, radius, canvas): + self.radius = radius + Command.__init__(self, canvas) + + def __call__(self, canvas): + return oil_paint(canvas.current_image, radius=self.radius) + class Despeckle(Command): TEXT = _('De-speckle image') @@ -380,6 +394,11 @@ class Canvas(QWidget): self.undo_stack.push(Normalize(self)) return True + @imageop + def oilify_image(self, radius=4.0): + self.undo_stack.push(Oilify(radius, self)) + return True + # The selection rectangle {{{ @property def dc_size(self): diff --git a/src/calibre/gui2/tweak_book/editor/image.py b/src/calibre/gui2/tweak_book/editor/image.py index 028a03ee11..c74ba8871a 100644 --- a/src/calibre/gui2/tweak_book/editor/image.py +++ b/src/calibre/gui2/tweak_book/editor/image.py @@ -274,6 +274,7 @@ class Editor(QMainWindow): m.addAction(_('Blur image'), self.blur_image) m.addAction(_('De-speckle image'), self.canvas.despeckle_image) m.addAction(_('Improve contrast (normalize image)'), self.canvas.normalize_image) + m.addAction(_('Make image look like an oil painting'), self.oilify_image) self.info_bar = b = self.addToolBar(_('Image information bar')) b.setObjectName('image_info_bar') @@ -322,6 +323,12 @@ class Editor(QMainWindow): if ok: self.canvas.blur_image(sigma=val) + def oilify_image(self): + val, ok = QInputDialog.getDouble(self, _('Oilify image'), _( + 'The strength of the operation (higher numbers have larger effects)'), value=4, min=0.1, max=20) + if ok: + self.canvas.oilify_image(radius=val) + def launch_editor(path_to_edit, path_is_raw=False): app = QApplication([]) if path_is_raw: