fix
This commit is contained in:
parent
15f85292ef
commit
d7746fa85b
|
@ -1,9 +1,6 @@
|
|||
from pymongo import UpdateOne
|
||||
from lib.all import *
|
||||
import oss2
|
||||
import os
|
||||
import pyheif
|
||||
from PIL import Image
|
||||
|
||||
service_name = 'compress'
|
||||
log_dir = '/app/log'
|
||||
|
@ -12,6 +9,7 @@ logger = Logger(service_name, log_dir=log_dir)
|
|||
access_key_id = "LTAI5tAdu5LRvZwm4LJa21Fo"
|
||||
access_key_secret = "WGvSQsDralTfFAAxhEqLBOgbXqflHo"
|
||||
endpoint_internal = "https://oss-cn-hangzhou-internal.aliyuncs.com"
|
||||
# endpoint_internal = "https://oss-cn-hangzhou.aliyuncs.com"
|
||||
bucket_name = "wishpal-ironfan-media"
|
||||
|
||||
|
||||
|
@ -29,12 +27,24 @@ class S:
|
|||
def __del__(self):
|
||||
self.col_image.close()
|
||||
|
||||
def proc_oen(self):
|
||||
form = "jpeg" # 设置输出图片格式,需要转换成png时,引号内换成png即可
|
||||
def upload_img_to_oss(self, local_path: str, oss_src_id: str):
|
||||
return self.bucket.put_object_from_file(oss_src_id, local_path)
|
||||
|
||||
img = pyheif.read("734f-684a-46e1-8f45-5ee57091f75c.heic") # 读取HEIC图片文件
|
||||
img_bytes = Image.frombytes(mode=img.mode, size=img.size, data=img.data) # 读取图片参数
|
||||
img_bytes.save("734f-684a-46e1-8f45-5ee57091f75c.jpeg", format=form) # 保存图片为JPEG
|
||||
def heic_to_jpg_and_save(self, oss_src_id, local_path):
|
||||
style = "image/format,jpeg"
|
||||
return self.bucket.get_object_to_file(oss_src_id, local_path, process=style)
|
||||
|
||||
def proc_oen(self):
|
||||
# 获取所有heic图片
|
||||
q = {"fmt": "image/heic"}
|
||||
images = self.col_image.find(q, limit=5)
|
||||
for img in images:
|
||||
old_key = safe_get_str(img, "src_id")
|
||||
new_key = old_key + "_h2j"
|
||||
local_path = new_key + ".jpeg"
|
||||
|
||||
ret = self.heic_to_jpg_and_save(old_key, local_path)
|
||||
logger.Info("heic_to_jpg_and_save, ret: {}".format(ret))
|
||||
|
||||
|
||||
s = S()
|
||||
|
|
Loading…
Reference in New Issue