Python based on PyGraphics package image interception function method

  • 2020-06-19 10:41:31
  • OfStack

An example of Python based on PyGraphics package is presented in this paper. To share for your reference, specific as follows:

Install PyGraphics package first (python import media module)

There is one code to import media. Open IDLE which comes with python and type:


>>>import media

There is no media module!

The original media module is not the standard module of the system, which can only be used after installing the third party software. This library is in PyGraphics, but PyGraphics depends on 1 other library. It can be installed (refer here: http: / / packages python. org/PyGraphics/install html) :

Download: Python Imaging Library 1.1.7 for Python 2.7-- > The installation
Download: pygame - 1.9.1. win32 - py2. 7. msi - > The installation
Download: numpy 1.6.1 - win32 - superpack - python2. 7. exe - > The installation
Download: ampy - 1.2.3. win32. exe -- -- > The installation
http: / / pragprog com/titles/gwpy/download source_code Download gwpy - code. After zip code - after decompression > install-- > PyGraphics-2.0.win32.exe-- > The installation

If you want to use tests in the PyGraphics package, you must download and install the Nose package as follows:

First, download: setuptool-- > The installation

Next, turn on cmd-- > Enter the command prompt line and keep your computer connected to the external network. Type C:\Python27\Scripts\ easy_ES92en enter and the computer will automatically download from the Internet.

Note: C:\Python27 refers to the folder where python is, you can change if different!

You can now use all the contents of the PyGraphics package, such as media, picture, pixel, color, sound, etc.

Ok, now in IDLE pilot 1 import media, no more errors!

Reference:

http://packages.python.org/PyGraphics/
http://packages.python.org/PyGraphics/install.html

Open the picture


>>>import media
>>>f=media.choose_file()
>>>pic=media,load_picture(f)
>>>media.show(pic)

Gets the length and width of the image


>>>pic.get_width()
...
>>>pic.get_height()
...
>>>pic.title
...

Clipping of pictures


>>>media.crop_picture(pic,150,50,450,300) # The top left corner ( 150,50 ) Lower right corner ( 450,300 ) 
>>>media.show(pic)
>>>media.save_as(pic,'new_.jpg')

More about Python related content interested readers to view this site project: Python pictures skills summary, "Python data structure and algorithm tutorial", "Python Socket programming skills summary", "Python function using techniques", "Python string skills summary", "Python introduction and advanced tutorial" and "Python file and directory skills summary"

I hope this article has been helpful for Python programming.


Related articles: