[Python] python 一句话代码将图片变亮或者变暗 →→→→→进入此内容的聊天室

来自 , 2019-03-08, 写在 Python, 查看 121 次.
URL http://www.code666.cn/view/8da57fac
  1. # do pixel math on an image using the PIL image library
  2. # free from:  http://www.pythonware.com/products/pil/index.htm
  3. # Python23 tested      vegaseat     22jan2005
  4. import Image
  5. # open an image file (.jpg or.png) you have in the working folder
  6. im1 = Image.open("Audi.jpg")
  7. # multiply each pixel by 0.9 (makes the image darker)
  8. # works best with .jpg and .png files, darker < 1.0 < lighter
  9. # (.bmp and .gif files give goofy results)
  10. # note that lambda is akin to a one-line function
  11. im2 = im1.point(lambda p: p * 0.9)
  12. # brings up the modified image in a viewer, simply saves the image as
  13. # a bitmap to a temporary file and calls viewer associated with .bmp
  14. # make certain you have associated an image viewer with this file type
  15. im2.show()
  16. # save modified image to working folder as Audi2.jpg
  17. im2.save("Audi2.jpg")
  18. #//python/5727

回复 "python 一句话代码将图片变亮或者变暗"

这儿你可以回复上面这条便签

captcha