Python | PIL Attributes

PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities.

Attributes:

Attribute defines the various property of an object, element or file. In the image, attribute refers to the size, filename, format or mode, etc. of the image.

Image used is:



Instances of the Image class have the following attributes:

PIL.Image.filename: The filename or path of the source file. Only images created with the factory function open have a filename attribute. If the input is a file-like object, the filename attribute is set to an empty string.

Syntax: PIL.Image.filename

Type: py:class: string
filter_none

edit
close

play_arrow

link
brightness_4
code

from PIL import Image
im1 = Image.open(r"C:\Users\sadow984\Desktop\i3.PNG")
  
im2 = im1.filename
print(im2)

chevron_right


Output:

C:\Users\sadow984\Desktop\r1.PNG

 
PIL.Image.format: The file format of the source file. For images created by the library itself (via a factory function, or by running a method on an existing image), this attribute is set to None.

Syntax: PIL.Image.format

Type: string or None
filter_none

edit
close

play_arrow

link
brightness_4
code

from PIL import Image
im1 = Image.open(r"C:\Users\sadow984\Desktop\i3.PNG")
  
im2 = im1.format
print(im2)

chevron_right


Output:

PNG

 
PIL.Image.mode: Image mode. This is a string specifying the pixel format used by the image. Typical values are “1”, “L”, “RGB”, or “CMYK.” See Modes for a full list.

Syntax: PIL.Image.mode

Type: string 
filter_none

edit
close

play_arrow

link
brightness_4
code

from PIL import Image
im1 = Image.open(r"C:\Users\sadow984\Desktop\i3.PNG")
  
im2 = im1.mode
print(im2)

chevron_right


Output:

P

 
PIL.Image.size: Image size, in pixels. The size is given as a 2-tuple (width, height).

Syntax: PIL.Image.size

Type: (width, height) 
filter_none

edit
close

play_arrow

link
brightness_4
code

from PIL import Image
im1 = Image.open(r"C:\Users\sadow984\Desktop\i3.PNG")
  
im2 = im1.size
print(im2)

chevron_right


Output:

(225, 225)


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : nidhi_biet



Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.