def convert_svg_to_bitmap(source, target): svg_renderer = QSvgRenderer(source) height = svg_renderer.defaultSize().height() width = svg_renderer.defaultSize().width() new_image = QImage(width, height, QImage.Format_ARGB32) painter = QPainter(new_image) svg_renderer.render(painter) new_image.save(target) painter.end()
def embeded_image_scale_to_width(src_path, width_scalar): qimage = QImage(src_path) new_width = width_scalar * qimage.width() qimage = qimage.scaledToWidth(new_width, Qt.SmoothTransformation) data = QByteArray() buffer = QBuffer(data) buffer.open(QIODevice.WriteOnly) qimage.save(buffer, "JPG") base64_data = data.toBase64().data().decode('ascii') return "data:image/jpeg;base64,{base64_data}".format( base64_data=base64_data)