I have links for PNG PNG images that I want to download, "convert to thumbnails" and save to PDF using Python and Cairo.
Now I have a working code, but I do not know how to control the size of the image on paper. Is there a way to resize the PyCairo surface to the dimensions I want (which happens less than the original)? I want the original pixels to be “squeezed” to a higher resolution (on paper).
In addition, I tried the Image.rescale() function from PIL, but it returns me the result of 20x20 pixels (from the original image 200x200 pixels, which is not an example of a banner in the code). I want the 200 × 200 image to be applied to a 20 × 20 mm square on paper (instead of a 200 × 200 mm square, as I get now)
My current code is:
#!/usr/bin/python import cairo, urllib, StringIO, Image
Please note that a beautiful Cairo banner is not even suitable for the page ... The ideal result would be that I could control the width and height of this image in units of user space (in this case, millimeters) to create a nice header image, eg.
Thanks for reading and for any help or comment!
python resize pdf cairo geometry-surface
heltonbiker
source share