Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DPI doesn't work for CMYK save #3970

Closed
007gzs opened this issue Jul 15, 2019 · 5 comments
Closed

DPI doesn't work for CMYK save #3970

007gzs opened this issue Jul 15, 2019 · 5 comments

Comments

@007gzs
Copy link

007gzs commented Jul 15, 2019

What did you do?

save a jpeg image where param dpi

What did you expect to happen?

the new jpg image dpi same as the dpi param

What actually happened?

new file doesn't have dpi info

What are your OS, Python and Pillow versions?

  • OS: window7/centos 7
  • Python: 2.7.5/3.6.8
  • Pillow: 6.1.0
    from PIL import Image
    img = Image.open("test1.jpg")
    print("test1.jpg", img.info.get('dpi'))
    other_img = Image.open("test2.jpg")
    print("test2.jpg", other_img.info.get('dpi'))
    img.paste(other_img.resize((200, 200), Image.LANCZOS), (0, 0))
    img.save("test3.jpg", dpi=(300, 300), quality="keep")
    new_img = Image.open("test3.jpg")
    print("test3.jpg", new_img.info.get('dpi'))

sample_file.zip

@radarhere
Copy link
Member

Looks like this is because the image is in CMYK mode -

from PIL import Image
im = Image.new("CMYK", (100, 100))
im.save("out.jpg", dpi=(300, 300))

new_im = Image.open("out.jpg")
print("out.jpg", new_im.info.get('dpi'))  # out.jpg None

@radarhere radarhere added the JPEG label Jul 15, 2019
@radarhere radarhere changed the title Image.save jpeg file dpi param doesn't work DPI doesn't work for CMYK save Jul 15, 2019
@radarhere
Copy link
Member

You may or may not be interested in this as an immediate solution - remove the 'quality' argument, convert to RGB, and it works -

from PIL import Image
img = Image.open("test1.jpg")
print("test1.jpg", img.info.get('dpi'))
other_img = Image.open("test2.jpg")
print("test2.jpg", other_img.info.get('dpi'))
img.paste(other_img.resize((200, 200), Image.LANCZOS), (0, 0))
img.convert("RGB").save("test3.jpg", dpi=(300, 300))
new_img = Image.open("test3.jpg")
print("test3.jpg", new_img.info.get('dpi'))

@007gzs
Copy link
Author

007gzs commented Jul 15, 2019

but I need to save it in CMYK format for my users to print.

@radarhere
Copy link
Member

Is saving it as TIFF an option?

from PIL import Image
img = Image.open("test1.jpg")
print("test1.jpg", img.info.get('dpi'))
other_img = Image.open("test2.jpg")
print("test2.jpg", other_img.info.get('dpi'))
img.paste(other_img.resize((200, 200), Image.LANCZOS), (0, 0))
img.save("test3.tiff", dpi=(300, 300), quality="keep")
new_img = Image.open("test3.tiff")
print("test3.tiff", new_img.info.get('dpi'))

@radarhere
Copy link
Member

Actually, I've realised that this is a duplicate of #1676

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants