代码拉取完成,页面将自动刷新
同步操作将从 Gitee 极速下载/deoldify 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import os
import requests
import random
import _thread as thread
from uuid import uuid4
import numpy as np
import skimage
from skimage.filters import gaussian
from PIL import Image
def compress_image(image, path_original):
size = 1920, 1080
width = 1920
height = 1080
name = os.path.basename(path_original).split('.')
first_name = os.path.join(os.path.dirname(path_original), name[0] + '.jpg')
if image.size[0] > width and image.size[1] > height:
image.thumbnail(size, Image.ANTIALIAS)
image.save(first_name, quality=85)
elif image.size[0] > width:
wpercent = (width/float(image.size[0]))
height = int((float(image.size[1])*float(wpercent)))
image = image.resize((width,height), PIL.Image.ANTIALIAS)
image.save(first_name,quality=85)
elif image.size[1] > height:
wpercent = (height/float(image.size[1]))
width = int((float(image.size[0])*float(wpercent)))
image = image.resize((width,height), Image.ANTIALIAS)
image.save(first_name, quality=85)
else:
image.save(first_name, quality=85)
def convertToJPG(path_original):
img = Image.open(path_original)
name = os.path.basename(path_original).split('.')
first_name = os.path.join(os.path.dirname(path_original), name[0] + '.jpg')
if img.format == "JPEG":
image = img.convert('RGB')
compress_image(image, path_original)
img.close()
elif img.format == "GIF":
i = img.convert("RGBA")
bg = Image.new("RGBA", i.size)
image = Image.composite(i, bg, i)
compress_image(image, path_original)
img.close()
elif img.format == "PNG":
try:
image = Image.new("RGB", img.size, (255,255,255))
image.paste(img,img)
compress_image(image, path_original)
except ValueError:
image = img.convert('RGB')
compress_image(image, path_original)
img.close()
elif img.format == "BMP":
image = img.convert('RGB')
compress_image(image, path_original)
img.close()
def blur(image, x0, x1, y0, y1, sigma=1, multichannel=True):
y0, y1 = min(y0, y1), max(y0, y1)
x0, x1 = min(x0, x1), max(x0, x1)
im = image.copy()
sub_im = im[y0:y1,x0:x1].copy()
blur_sub_im = gaussian(sub_im, sigma=sigma, multichannel=multichannel)
blur_sub_im = np.round(255 * blur_sub_im)
im[y0:y1,x0:x1] = blur_sub_im
return im
def download(url, filename):
data = requests.get(url).content
with open(filename, 'wb') as handler:
handler.write(data)
return filename
def generate_random_filename(upload_directory, extension):
filename = str(uuid4())
filename = os.path.join(upload_directory, filename + "." + extension)
return filename
def clean_me(filename):
if os.path.exists(filename):
os.remove(filename)
def clean_all(files):
for me in files:
clean_me(me)
def create_directory(path):
os.makedirs(os.path.dirname(path), exist_ok=True)
def get_model_bin(url, output_path):
if not os.path.exists(output_path):
create_directory(output_path)
cmd = "wget -O %s %s" % (output_path, url)
print(cmd)
os.system(cmd)
return output_path
#model_list = [(url, output_path), (url, output_path)]
def get_multi_model_bin(model_list):
for m in model_list:
thread.start_new_thread(get_model_bin, m)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。