程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Edit picture pixels, money? It doesnt exist. Ill teach you to use Python to change the size and color of the picture and splice the picture

編輯:Python
# coding=utf-8
from PIL import Image
def color_picture(filepath):
print(' Modify screenshot color ...')
# Picture enlargement
img = Image.open(filepath)
# Convert the picture into a grayscale image
xin_img = img.convert('L')
# xin_img.show()
# Image binarization , Picture by Grey background Variable
threshold = 127 # Binarization threshold , The default is 127
t_list = []
for i in range(256):
if i < threshold:
t_list.append(0)
else:
t_list.append(1)
# print(t_list)
new_img = xin_img.point(t_list, '1')
# preservation The changed picture
new_name = filepath.replace('%s' % filepath[-4:], '') + '_new_' + filepath[-4:]
new_img.save(new_name)
# new_img.show()
return new_name
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
# coding=utf-8
from PIL import Image
def size_picture(filepath):
print(' Modify screenshot size ...')
# Picture enlargement
img = Image.open(filepath)
width, height = img.size
# print(img.size, width, height) # (553, 432) 553 432
new_img = img.resize((960, 720), Image.ANTIALIAS)
# preservation The changed picture
new_name = filepath.replace('%s' % filepath[-4:], '') + '_new_' + filepath[-4:]
new_img.save(new_name)
# new_img.show()
return new_name
if __name__ == '__main__':
'''
Change picture size or Color etc. , And save New picture , Return new picture name
'''
filepath = 'img_chi_tu_canshu.jpg'
size_picture(filepath)

11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111

# coding=utf-8
from PIL import Image
import os
def mergei(images):
heigh_size = 0
width_size = 0
for i in range(len(images)):
img = Image.open(images[i])
print(img.size)
heigh_size = img.size[1]
width_size += img.size[0]
# heigh_size = 720
# width_size = 960
print('heght_size = %s <--> width_size = %s ' % (heigh_size, width_size))
imagefile = []
for j in range(2):
imagefile.append(Image.open(images[j]))
target = Image.new('RGB', (width_size, heigh_size))
# target.save('9999999.jpg')
print(target.size)
left = 0
right = width_size/2
image = Image.open(images[0])
target.paste(image, (0, 0))
# for image in imagefile:
# print('--------', left, 0, right, heigh_size)
# target.paste(image, (left, 0, right, heigh_size))
# left += heigh_size
# right += heigh_size
quality_value = 100
target.save('img_00_%s.jpg' % (left), quality=quality_value)
left = 1
image = Image.open(images[1])
target = Image.open('img_00_0.jpg')
target.paste(image, (928, 0, 928*2, 1920))
target.save('img_00_%s.jpg' % (left), quality=quality_value)
'''
(928, 1920)
(928, 1920)
heght_size = 1920 <--> width_size = 1856
(1856, 1920)
'''
if __name__ == '__main__':
# Picture splicing
images = ['img_shen_fen_zheng01.jpg', 'img_shen_fen_zheng02.jpg']
mergei(images)

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved