Notification texts go here Contact Us Buy Now!

How to check whether a JPEG image is color or gray scale using only Python stdlib

Python Image Library (PIL) is a library that provides support for opening, manipulating, and saving many different image file formats. Here is how you can check whether a JPEG image is color or grayscale using PIL:

```python import Image im = Image.open("lena.jpg") if im.mode == "RGB": print("Color Image") else: print("Grayscale Image") ```

The im.mode attribute returns the mode of the image. For color images, the mode will be "RGB". For grayscale images, the mode will be "L".

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.