diff --git a/src/calibre/web/feeds/news.py b/src/calibre/web/feeds/news.py index 4a2696d24e..e915a6c0b2 100644 --- a/src/calibre/web/feeds/news.py +++ b/src/calibre/web/feeds/news.py @@ -1075,46 +1075,22 @@ class BasicNewsRecipe(Recipe): img.save(open(out_path, 'wb'), 'JPEG') def prepare_masthead_image(self, path_to_image, out_path): - import calibre.utils.PythonMagickWand as pw - from ctypes import byref from calibre import fit_image + from calibre.utils.magick import Image, create_canvas - with pw.ImageMagick(): - img = pw.NewMagickWand() - img2 = pw.NewMagickWand() - frame = pw.NewMagickWand() - p = pw.NewPixelWand() - if img < 0 or img2 < 0 or p < 0 or frame < 0: - raise RuntimeError('Out of memory') - if not pw.MagickReadImage(img, path_to_image): - severity = pw.ExceptionType(0) - msg = pw.MagickGetException(img, byref(severity)) - raise IOError('Failed to read image from: %s: %s' - %(path_to_image, msg)) - pw.PixelSetColor(p, 'white') - width, height = pw.MagickGetImageWidth(img),pw.MagickGetImageHeight(img) - scaled, nwidth, nheight = fit_image(width, height, self.MI_WIDTH, self.MI_HEIGHT) - if not pw.MagickNewImage(img2, width, height, p): - raise RuntimeError('Out of memory') - if not pw.MagickNewImage(frame, self.MI_WIDTH, self.MI_HEIGHT, p): - raise RuntimeError('Out of memory') - if not pw.MagickCompositeImage(img2, img, pw.OverCompositeOp, 0, 0): - raise RuntimeError('Out of memory') - if scaled: - if not pw.MagickResizeImage(img2, nwidth, nheight, pw.LanczosFilter, - 0.5): - raise RuntimeError('Out of memory') - left = int((self.MI_WIDTH - nwidth)/2.0) - top = int((self.MI_HEIGHT - nheight)/2.0) - if not pw.MagickCompositeImage(frame, img2, pw.OverCompositeOp, - left, top): - raise RuntimeError('Out of memory') - if not pw.MagickWriteImage(frame, out_path): - raise RuntimeError('Failed to save image to %s'%out_path) - - pw.DestroyPixelWand(p) - for x in (img, img2, frame): - pw.DestroyMagickWand(x) + img = Image() + img.open(path_to_image) + width, height = img.size + scaled, nwidth, nheight = fit_image(width, height, self.MI_WIDTH, self.MI_HEIGHT) + img2 = create_canvas(width, height) + frame = create_canvas(self.MI_WIDTH, self.MI_HEIGHT) + img2.compose(img) + if scaled: + img2.size = (nwidth, nheight, 'LanczosFilter', 0.5) + left = int((self.MI_WIDTH - nwidth)/2.0) + top = int((self.MI_HEIGHT - nheight)/2.0) + frame.compose(img2, left, top) + frame.save(out_path) def create_opf(self, feeds, dir=None): if dir is None: