Geo
Geo

Reputation: 96897

Is it possible to reduce an image's depth using PIL?

Is it possible to reduce the depth of an image using PIL? Say like going to 4bpp from a regular 8bpp.

Upvotes: 5

Views: 9432

Answers (2)

c2o93y50
c2o93y50

Reputation: 231

This can be done using the changeColorDepth function in ufp.image module. this function only can reduce color depth(bpp)

import ufp.image
import PIL
im = PIL.Image.open('test.png')
ufp.image.changeColorDepth(im, 16) # change to 4bpp(this function change original PIL.Image object)
im.save('changed.png')

Upvotes: 0

Alex Martelli
Alex Martelli

Reputation: 882113

You can easily convert image modes (just call im.convert(newmode) on an image object im, it will give you a new image of the new required mode), but there's no mode for "4bpp"; the modes supported are listed here in the The Python Imaging Library Handbook.

Upvotes: 6

Related Questions