最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

resize - Exporting with correct size and resolution in GIMP - Stack Overflow

programmeradmin2浏览0评论

When i do the following thing manually: go to image, scale image, change the x resolution 600 dpi and the y resolution to 600 dpi. The width and height change accordingly to the proper size in mm. If I then export the image to png with compression to zero: the png is saved in the correct manner. If I reopen the file. the resolution and the size in MM are both still correct.

If I do the same through code. The image file has a 72 dpi and a width and height of 996 mm by 758 mm. I understand that technically this is the same but how can I make the code act in the same way as the manual actions.

desired_dpi = 600.0

width, height = pdb.gimp_image_width(image), pdb.gimp_image_height(image)

new_width = width / (pdb.gimp_image_get_resolution(image)[0] / desired_dpi)
new_height = height / (pdb.gimp_image_get_resolution(image)[1] / desired_dpi)

pdb.gimp_image_scale(image, new_width, new_height) 
pdb.gimp_image_set_resolution(image, desired_dpi, desired_dpi)


merged_layer = pdb.gimp_image_merge_visible_layers(image, CLIP_TO_IMAGE)

pdb.file_png_save(
        image,
        merged_layer,
        output_path,
        output_path,
        0,  # interlace
        0,  # compression (0-9, now set to 0)
        0,  # bKGD
        0,  # gAMA
        0,  # oFFs
        0,  # pHYs
        1   # TIFF warning
    )

 pdb.gimp_image_delete(image)

When i do the following thing manually: go to image, scale image, change the x resolution 600 dpi and the y resolution to 600 dpi. The width and height change accordingly to the proper size in mm. If I then export the image to png with compression to zero: the png is saved in the correct manner. If I reopen the file. the resolution and the size in MM are both still correct.

If I do the same through code. The image file has a 72 dpi and a width and height of 996 mm by 758 mm. I understand that technically this is the same but how can I make the code act in the same way as the manual actions.

desired_dpi = 600.0

width, height = pdb.gimp_image_width(image), pdb.gimp_image_height(image)

new_width = width / (pdb.gimp_image_get_resolution(image)[0] / desired_dpi)
new_height = height / (pdb.gimp_image_get_resolution(image)[1] / desired_dpi)

pdb.gimp_image_scale(image, new_width, new_height) 
pdb.gimp_image_set_resolution(image, desired_dpi, desired_dpi)


merged_layer = pdb.gimp_image_merge_visible_layers(image, CLIP_TO_IMAGE)

pdb.file_png_save(
        image,
        merged_layer,
        output_path,
        output_path,
        0,  # interlace
        0,  # compression (0-9, now set to 0)
        0,  # bKGD
        0,  # gAMA
        0,  # oFFs
        0,  # pHYs
        1   # TIFF warning
    )

 pdb.gimp_image_delete(image)
Share Improve this question asked Jan 20 at 18:35 Gerard B.Gerard B. 534 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

If you want a given size in millimeters with a given resolution, the current resolution is completely irrelevant. Just do:

new_width=(required_width_in_millimeters/25.4)*desired_dpi

Your current computation assumes that the image already has the right size in pixels for the required print size and current definition.

Also, compression is irrelevant here, it just sets how hard the PNG algorithm tries to compress, the final image will always be pixel-perfect. With higher compression settings, you just waste CPU, but using 1-2 usually gives vastly smaller files than 0.

发布评论

评论列表(0)

  1. 暂无评论