Python Processing Pictures

Source: Internet
Author: User
Tags flip picture image processing library

PIL is the most common image processing library in Python, the PIL module in Python 2.x, replaced with pillow module in Python 3.x, installing Pil:pip install Pillow

1, Python view some properties of the picture

#!/usr/bin/env python#-*-coding:utf-8-*-From PILImportImageimage= Image.Open("dora.jpg")#open a Picture objectPrint(Image.format)#view the format of the image with the result ' JPEG 'Print(image.size)#View the size of the picture, and the result is (800,450) pixels of width and height, respectivelyPrint(Image.mode)#View the mode of the picture, the result is ' RGB ', other modes are bitmap mode, grayscale mode, Duotone mode, etc.

2. Python Resize Image

# !/usr/bin/env python#-*-coding:utf-8-*-  import= Image. Open ("dora.jpg")    # Open a Picture object  = Image.resize ((+))    # Adjust the picture to a width of 128 pixels, 128 pixels high
Out.show () # view pictures

3. Python Rotate Picture

# !/usr/bin/env python#-*-coding:utf-8-*-  import= Image. Open ("dora.jpg")    # open a Picture object out = image.rotate            #  rotate the picture counterclockwise 45 degrees out.show ()                        # View pictures

4. Python Flip Picture

# !/usr/bin/env python#-*-coding:utf-8-*-  import= Image. Open ("dora.jpg")                  # open a Picture object out = Image.transpose (image.flip_left_right)    #  Flip the picture around if you want to flip the argument up and down to ' Image.flip_top_bottom 'out.show ()                                      #  View pictures

Python Processing Pictures

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.