[Python-15/100] and office document processing images (Image and office document processing)

Copyright: Public Number: Fresh Site. QQ group: 690 274 ​​159. Reprinted with my blog, please attach a reprint address, thank you! ^ _ ^ I'm a hip-hop program ape freshman. https://blog.csdn.net/wuhongxia29/article/details/90901226

Day15 images and office document processing (Image and office document processing)

Operation image

1. Color

  • Fine three primary colors: RGY
  • Shade the three primary colors: RGB
name RGBA values
Red (255, 0, 0, 255)
Green (0, 255, 0, 255)
Blue (0, 0, 255, 255)
Yellow (255, 255, 0, 255)
White (255, 255, 255, 255)
Gray (128, 128, 128, 255)
Black (0, 0, 0, 255)
Purple (128, 0, 128, 255)

2. pixels (Pixel)

Pillow operation image with

Installation pillow

pip install pillow

example

from PIL import Image, ImageFilter


image = Image.open('cute_man.jpg')
image2 = Image.open('fresh_man.jpg')
print('format:%s, size:%s, mode:%s' % (image.format, image.size, image.mode))

# 1.裁剪图像
rect = 59, 8, 411, 312  # left, upper, right, down
cute_head = image.crop(rect)

# 2.生成缩略图
size = 128, 128
image.thumbnail(size)

# 3.缩放和粘贴图像
width, height = cute_head.size
image2.paste(cute_head.resize((int(width / 1.5), int(height / 1.5))), (250, 200))

# 4.旋转和翻转
image.rotate(180).show()  # 180度旋转
image.transpose(Image.FLIP_LEFT_RIGHT).show()  # 左右翻转

# 5.操作像素
for x in range(52, 406):
    for y in range(12, 312):
        image.putpixel((x, y), (255, 0, 0))  # 红色
image.show()  # 显示图片

# 6.滤镜效果
image.filter(ImageFilter.CONTOUR).show()

With Excel

Modules:

Word processing

Modules:

  • python-docx

Processing PDF (Portable Document Format)

Modules:

  • pypdf2
  • reportlab

Guess you like

Origin blog.csdn.net/wuhongxia29/article/details/90901226