I'm attempting to convert a JPEG file with, 200 dpi, to a PDF file, however, when I save the file as a PDF I think it's changing the dpi to 72, and thus making the image larger. I had a similar problem when initially trying to scale my JPEG image to a smaller size, and was able to solve that by specifying the dpi when I save the image.
im = Image.open("Image.jpg")
dpi=im.info['dpi']
if im.size == (2592, 1728):
out = im.resize((1188,792), Image.ANTIALIAS)
elif im.size == (1728,2592):
out = im.resize((792,1188), Image.ANTIALIAS)
out.save(project, dpi=dpi)
Now when I try to save this JPEG as a PDF, specifying the dpi doesn't seem to make any difference, and I get an image that is larger than my original that looks like it has a lower dpi. Is there a way to mantain a consistent resolution when converting from JPEG to PDF using PIL? Or is there a better way for me to go about doing this?
This is what I have for converting a directory of files from JPEG to PDF:
for infile in listing:
outfile = destpath + os.path.splitext(infile)[0] + ".pdf"
current = path + infile
if infile != outfile:
im = Image.open(current)
dpi=im.info['dpi']
im.save(outfile, "PDF", Quality = 100)