How can you render an SVG to a png in a specific size (python) - python-3.x

I am Working on a small Image comparing script where the reference images are generated as SVGs and the compare images are PNGs.
I can transform the SVG files to PNG (using svglib and renderpm) but canĀ“t specify the size I want them to be generated as(renderscale seems to cut of a part of the picture), but I need to get them to the same size for the compare functions and resizing the pngs nullifyes the whole purpose of vector graphics in itself. Any Ideas?
Regards a python noob

Related

SkiaSharp support for color quantization for PNG files

I'm looking for an all-in-one solution for processing web images
Resizing
Cropping
Save as WEBP / JPEG / PNG
Drawing simple rectangles
Adding text
Reducing colors (quantization) for PNG
The only thing I'm not clear about is PNG quantization. Currently I'm using pngquant which works great, but I'd prefer to do everything in one place.
I see the SkiaSharp has SKImage.Encode() which takes a quality parameter. However there's no explanation as to what it actually is. Will this give me color quantization for PNG files? If not, is there something else in the library to do this?

Pdf to svg is not perfect

I have tried nearly every library to convert pdf to svg, Following are the results of them
gs or ghostscript and imagemagick: The size gets multiplied by 100
pdf2svg and inkscape: The image on the top of the pdf is not at all accurate here are the links to the pdf and the svg.
PDF: https://drive.google.com/open?id=0BxyQR1owWa_pcnhhSk5wQWJGMVk
SVG: https://drive.google.com/open?id=0BxyQR1owWa_pVnhoLVlob1U2d1k
Please suggest me if I am missing something that needs to be done.
The Ghostscript SVG output device is seriously deprecated and no longer supported (or indeed built into the standard Ghostscript binary).
In any event, you need to be aware that PDF is a very rich graphics model, and it is simply not possible to reproduce every possible nuance of a PDF using the SVG graphics model, in particular fonts are a problem, but so is almost any kind of transparency. When that occurs Ghostscript will render the PDF to an image, and insert that into an SVG file. Almost certainly that's why you are seeing the SVG file being considerably larger than the PDF file. You should be able to use the -r switch to control the resolution of the rendering, allowing you to trade off quality for size.
Even if the whole file isn't converted to a bitmap, its possible that large portions of it are, or that the bitmap compression in SVG is less good than for PDF (or GS isn't taking advantage of all the possibilities). FWIW the PDF file uncompressed runs to > 4MB.

SVG as texture gets blended in some way

I've got a strange behaviour when using SVG as textures in three.js.
When loading the first texture all is fine but the second one contains the first one when used as a texture (they share the same viewBox in the SVG but that shouldn't be an issue normally). Stuff is working when using PNGs or other image files.
Here is a minimal example:
http://jsbin.com/xeyigahata/1/edit?html,js,output
Thx!

How to convert SVG map to PNG without losing border quality?

I downloaded this svg map and used ImageMagick to convert to PNG format. However, my output PNG images don't look very well: the white borders between countries almost don't show. On the other hand, the rendered versions on the Wikimedia site look great.
Is there any option I can pass to ImageMagick to prioritize borders?

Graph is too large for cairo-renderer bitmaps

Im trying to use pyreverse to generate UML images for a project source code. When I run the pyreverse command and specify to generate png images, it runs and then after a while, it shows:
dot: graph is too large for cairo-renderer bitmaps. Scaling by 0.271394 to fit
dot: graph is too large for cairo-renderer bitmaps. Scaling by 0.333083 to fit
Then if I open either image, the text is unreadable because it got scaled.
Is there a way to just not scale, and let the image be large size?
Thanks
the option
-T svg
worked for me
Cairo's maximum bitmap size is 32767x32767 pixels, and dot will scale your graph to fit inside that area. As an alternative, you can tell pyreverse to generate PDF files, and use some other tool to convert to PNG, if you really need bitmaps.
in 2019, you can simply output the diagram as svg using:
-o svg

Resources