def eventFilter(self, obj, evt): if not (evt.type() == QEvent.Paint and self.save_png): return super().eventFilter(obj, evt) filename, oldsize = self.save_png self.save_png = () size = self._page.contentsSize().toSize() image = QImage(size, QImage.Format_ARGB32) painter = QPainter(image) self.render(painter) painter.end() success = image.save(filename, "png") self.resize(oldsize) mw.progress.finish() if success: showInfo("Image saved to %s!" % os.path.abspath(filename)) else: showCritical("Failed to save the image.") return super().eventFilter(obj, evt)
def eventFilter(self, obj, evt): if not(evt.type() == QEvent.Paint and self.save_png): return super().eventFilter(obj, evt) filename, oldsize = self.save_png self.save_png = () size = self._page.contentsSize().toSize() image = QImage(size, QImage.Format_ARGB32) painter = QPainter(image) self.render(painter) painter.end() success = image.save(filename, "png") self.resize(oldsize) mw.progress.finish() if success: showInfo("Image saved to %s!" % os.path.abspath(filename)) else: showCritical("Failed to save the image.") return super().eventFilter(obj, evt)
def SaveImageToMedia(imageData, editor): im = QImage.fromData(imageData) uname = namedtmp("pasteHTML-%d" % im.cacheKey()) if editor.mw.pm.profile.get("pastePNG", False): ext = ".png" im.save(uname + ext, None, 50) else: ext = ".jpg" im.save(uname + ext, None, 80) # invalid image? if not os.path.exists(uname + ext): return "" fname = editor.mw.col.media.addFile(uname + ext) return fname
def _processImage(self, mime): if not mime.hasImage(): return im = QImage(mime.imageData()) uname = namedtmp("paste") if self.editor.mw.pm.profile.get("pastePNG", False): ext = ".png" im.save(uname+ext, None, 50) else: ext = ".jpg" im.save(uname+ext, None, 80) # invalid image? path = uname+ext if not os.path.exists(path): return data = open(path, "rb").read() fname = self.editor._addPastedImage(data, ext) if fname: return self.editor.fnameToLink(fname)