A simple use of the PIL module for Python processing pictures

Source: Internet
Author: User

This article mainly introduces the Python processing picture's PiL module simple use method, involves Python uses the PiL module to realize to the picture sharpening, draws the line, the drawing ellipse and so on related skill, needs the friend to be possible to refer to under

The example of this article is about the simple use of the PIL module for Python processing pictures. Share to everyone for your reference. The implementation methods are as follows:

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59-60 #!/usr/bin/env python #encoding: utf-8 import Image class Myimg:def __init__ (s Elf, Open_file, save_file): self.img = Image.open (open_file) self.save_file = Save_file def change_size (self, percent=100 , Height=none, Width=none): ' percent: To determine the size of the height, width: to the specified height and width to determine the size ' if not (height and width): width,height = Self.img.size new_img = self.img.resize ((width*percent/100,height*percent/100), image.bilinear) New_img.save ( Self.save_file def rotation (self, Angle): "' Angle: Rotational degrees '" rot_img = self.img.rotate (angle) #旋转 Rot_img.save (self.s Ave_file def save_as (self, filename): "' FileName: Save as Picture format, directly according to suffix name ' self.img.save (filename) def draw_something ( Self): "' Use Imagedraw to draw graphics ' import Imagedraw draw = Imagedraw.draw (self.img) width,height = Self.img.size Draw.line (((0,0), (width-1,height-1)), fill=255) #画直线 Draw.line ((0,height-1), (width-1,0), fill=255) Draw.arc ((0,0,width-1,height-1), 0,360,fill=255) #画椭圆 Self.img.save (Self.save_file) def enhance_something (self): ' use imageenhance to enhance image effect ' import imageenhance Brightness = imageenhance.brightness (self.img) bright_img = brightness.enhance (2.0) # #亮度增强 Bright_img.save (self.save_ file) sharpness = imageenhance.sharpness (self.img) sharp_img = sharpness.enhance (7.0) #锐度增强 Sharp_img.save (self.save_ File) contrast = Imageenhance.contrast (self.img) #对比度增强 contrast_img = contrast.enhance (2.0) Contrast_img.save ( Self.save_file) If __name__ = = "__main__": file_name = r "D:test.png" Save_file = r "D:save.png" Saveas_file = r "D:save_as.b MP "oimg = myimg (file_name, Save_file) oimg. Change_size (oimg). Rotation (OIMG). Save_as (Saveas_file) oimg. Draw_something () oimg. Enhance_something ()

Original:

Processed Paint: (sharpened)

PS: In addition, there is another more commonly used modules, image module.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.