Commit c606ec23 authored by haowang's avatar haowang

fix upload image

parent c6034ea7
......@@ -142,14 +142,14 @@ class UploadImage(object):
文章图片剪切和下载
'''
def _deal_image_by_path(file_path):
def _deal_image_by_path(file_path, old_url):
img = cv2.imread(file_path)
if img:
high, width = img.shape[:2]
cropped = img[0:int(high / 10 * 9), 0:width]
pathes = new_path + "num" + str(i) + ".jpg"
cv2.imwrite(pathes, cropped)
new_url = self.upload_image_with_path(pathes)
sql = """UPDATE {} SET new_url = "{}" WHERE url = "{}" """.format(
table, str(new_url), str(tuple[i][1]))
......@@ -157,7 +157,16 @@ class UploadImage(object):
self.conn.commit()
else:
print('image open error : ', file_path)
_upload_picture(file_path, old_url)
def _upload_picture(file_path, old_url):
new_url = self.upload_image_with_path(file_path)
sql = """UPDATE {} SET new_url = "{}" WHERE url = "{}" """.format(
table, str(new_url), str(old_url))
self.cur.execute(sql)
self.conn.commit()
urls = self.find_all_url(content)
self.insert_picture_urls(table, urls, content_id, key_id)
......@@ -179,7 +188,7 @@ class UploadImage(object):
new_url = self.upload_image_with_path(pathes)
sql = """UPDATE {} SET new_url = "{}" WHERE url = "{}" """.format(
table, str(new_url), str(tuple[i][1]))
table, str(new_url), str(url))
self.cur.execute(sql)
self.conn.commit()
else:
......@@ -187,7 +196,7 @@ class UploadImage(object):
with open(pathes, 'wb') as f: # 打开写入到path路径里-二进制文件,返回的句柄名为f
f.write(r.content) # 往f里写入r对象的二进制文件
f.close()
_deal_image_by_path(pathes)
_deal_image_by_path(pathes, url)
def picture_process(self, path, new_path, table, pic_table, key_id, offset=0, count=10):
content_dict = self.gets_content_dict(table, key_id, offset, count)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment