保存从表单发布的图像,并使用“枕头”的“裁剪”对其进行剪切,然后调整大小并保存。
该程序在本地没有问题,但是在vps上部署后没有按指定的顺序剪切(当我上传5张图像时,一到两个图像没有按指定剪切)。
我只部署了git的数据。
我不明白原因。
能告诉我原因吗?
print(int(x))
print(int(y))
print(int(w))
print(int(h))
pp = ImageTable.objects.filter(sort_id = st.sort_id)
print(pp[count-1].image)
im = Image.open('media/' + str(pp[count-1].image)) #'str(pp[count-1].image)' is for example like 'images/test.png' images path
xx = int(x) + int(w)
yy = int(y) + int(h)
im = im.crop((int(x), int(y), int(xx), int(yy)))
im.resize(size=(200, 200), resample=Image.BOX).save('media/' + str(pp[count-1].image))
关于上面的代码。
该代码通过for函数循环并上传五个图像。
它为每个循环上传不同的图像,因为计数是每个循环加1。
通过打印调试,我确认x,y,w,h为指定值。
我几乎没有更改,但是我将数据库从db.sqlite3更改为postgresql。
这相关吗?
答案 0 :(得分:0)
此原因可能是数据库。 上传是成功的,但是调用图像并不成功。 当我使用“ .filter()”时,图像在db.sqlite3处被称为降序,但在postgresql中图像未被称为降序。 我需要使用“ .filter()。order('id')”。