How do Python PIL and PILLOW compress photos?

I wanted to write a program with Python 3.3 in which a frame is added to the picture. I am using the PIL package from Python for this. But the pictures that I get are less than a third than the original ones, and they lose enough focus / sharpness / brilliance. Where does Python compress / change the image and how (if possible) can I conquer it?

I might think of some passages that can be compressed.

  • I upload an image using PIL:

    img = Image.open(element)

  • I create a new image that is black:

    newImg = Image.new("RGB",(imgWidthNew,imgHightNew),(0,0,0,0))

  • I create a pixel map from my image and change some:

    pixels = newImg.load()

  • I insert a picture in the middle of black:

    newImg.paste (Image.open(element), (halfFrameWidth, halfFrameHight, imgWidth+halfFrameWidth, imgHight+halfFrameHight))

  • The new image is saved:

    newImg.save(path,dpi=[300,300])

I mostly upload .jpg images, but due to some problems I am extracting .bmp files.

 path = path[:path.rfind(".")] + fileEnding

, , . - Windows7 64BIT, Pillow 2.3.0 Python 3.3.

.

+3
1

JPEG :

newImg.save(path, 'JPEG', dpi=[300,300], quality=90)

, PNG:

newImg.save(path, 'PNG', dpi=[300,300])
+6

All Articles