Programmatically change image resolution

后端 未结 2 1472
感情败类
感情败类 2021-02-01 07:33

I have calculated that if I want my generated image to be A4 size @ 600dpi for print purpose, it needs to be 7016x4961px @ 72dpi. So, I generate it programmatically, then test

相关标签:
2条回答
  • 2021-02-01 08:14

    This code will resize a PNG image into 7016x4961 with PIL:

    size = 7016, 4961
    im = Image.open("my_image.png")
    im_resized = im.resize(size, Image.ANTIALIAS)
    im_resized.save("my_image_resized.png", "PNG")
    

    Perhaps a better approach would be to make your canvas x times bigger prior to printing, where x is a factor you have to figure out (7016x4961 in size for this particular image).

    0 讨论(0)
  • 2021-02-01 08:38

    If you have generated your image 7016 x 4961 px, it is already A4 at 600 dpi. So you don't need to resize it, you just have to set resolution information in file.

    You can do it with PIL:

    from PIL import Image
    
    im = Image.open("test.png")
    im.save("test-600.png", dpi=(600,600))
    
    0 讨论(0)
提交回复
热议问题