11/24/2023 0 Comments Imagemagic double size of pngSo I decided to dig a little deeper and solve that problem as it seemed to be a side effect of this approach and I think it has to do with the original density or dpi. I was getting "low poly" curves using the general approach of increasing the density. Os.remove(os.path.join(tempPath, fileNameRoot + '.svg')) Os.remove(os.path.join(tempPath, fileNameRoot + '.jpg')) Jpg = open(os.path.join(tempPath, fileNameRoot + '.jpg'), 'rb').read() WriteToFile(os.path.join(tempPath, fileNameRoot + '.svg'), xmldoc.toxml())Įxecute('convert -background "%s" %s %s' % (backgroundColor, os.path.join(tempPath, fileNameRoot + '.svg'), os.path.join(tempPath, fileNameRoot + '.jpg'))) Xmldoc.getElementsByTagName("svg").attributes.value = '%spx' % newHeight Xmldoc.getElementsByTagName("svg").attributes.value = '%spx' % newWidth NewHeight = int(newWidth / width * height) Height = float(xmldoc.getElementsByTagName("svg").('px')) Width = float(xmldoc.getElementsByTagName("svg").('px')) TempPath = os.path.join(self.rootFolder, 'data')įileNameRoot = 'temp_' + str(image.getID()) Here's my Python code, a function that will return the JPG file's content: import gzip, re, osįrom ynlib.files import ReadFromFile, WriteToFileįrom import parse, parseStringĭef SVGToJPGInMemory(svgPath, newWidth, backgroundColor): I've solved this issue through changing the width and height attributes of the tag to match my intended output size and then converting it using ImageMagick. Magick -density "%" button.svg button3.png In ImageMagick 7, you can do the computation in-line as follows: magick -density "%" button.svg button3.png So you can compute the needed density in proportion to the ratios of the dimensions and the densities. The input is 50 at default density of 96 (older versions of Inkscape may be using 92). Here is a small 50x50 button when rendered at the default density of 96: convert button.svg button1.png There is no "magic" parameter that will do what you want.īut, one can compute very simply the exact density needed to render the output. If Inkscape is installed on the system, ImageMagick will use it automatically. RSVG is a delegate that needs to be installed with ImageMagick. If you like the "Hall of Mirrors" effect, and want it 1200x1800 come what may, and to heck with the aspect ratio, do: convert -density 150 file.pdf -quality 100 -resize 1200x1800! res.In ImageMagick, one gets a better SVG rendering if one uses Inkscape or RSVG with ImageMagick than its own internal MSVG/XML rendered. If you want it no more than 1000px tall, and don't care about the width, do: convert -density 150 file.pdf -quality 100 -resize x1000 res.png If you want it no more than 800px wide, and don't care about the height, do: convert -density 150 file.pdf -quality 100 -resize 800x res.png So, in concrete terms, if you want it no more than 1500x2000 whilst retaining the original aspect ratio, do: convert -density 150 file.pdf -quality 100 -resize 1500x2000 res.png Just add a -resize WIDTHxHEIGHT in there after the conversion to set the size you want. Rather than assign the result to a variable like I did -I just do that because I generally want to use the variable later. In the foregoing, you can just use: identify -format "%" doc.pdf It comes out at 496x702 which is close to the width of 500 I wanted. It comes out at 702x994 - which is close to the height of 1000 I wantedĪnd if I use convert -density 60 doc.pdf a.jpg And if I then use convert -density 85 doc.pdf a.jpg So, if I use that on a file called doc.pdf that measures 595x842, it outputs 85 and 60 for the x and y density. So, let's let ImageMagick work out the x-resolution and the y-resolution you need to get your desired output size - it is easier to do it with ImageMagick's fx method because that works on both Windows and Linux and I happen to know you have ImageMagick installed already, whereas you may not have bc or anything on Windows to do maths: #!/bin/bash So, I think the identity you need is this: Required Resolution Required Heightīut remember that applies in both X- and Y-directions. From your comments, I think I understand better what you want now.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |