简体   繁体   English

我无法使用“枕头”的“裁剪”来剪切图像

[英]I can't cut of image using “crop” of “pillow”

Question about django.关于 django 的问题。

Posted image from form was saved and cut it using "crop" of "pillow" then resize and save.表单中发布的图像已保存并使用“枕头”的“裁剪”进行剪切,然后调整大小并保存。

the program was no problem in local, but it was not cuted as specified after deployed on vps (When I upload 5 images, the one or two images was not cuted as specified).程序在本地没有问题,但是部署在vps上后没有按指定剪切(当我上传5张图片时,其中一两张图片没有按指定剪切)。

I just only deployed data of git.我只是部署了git的数据。

I don't understand the cause.我不明白原因。

Could you tell me, if you know the cause.如果你知道原因,你能告诉我吗?

Code代码

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))

I Tried我试过了

About the code above.关于上面的代码。

the code is looped by for function and upload five images.代码由 function 循环并上传五张图片。

it upload different images for each loop because of count is plus 1 every loop.它为每个循环上传不同的图像,因为每个循环计数加 1。

I confirmed x,y,w,h was as specified value by using print debug.我通过使用打印调试确认 x,y,w,h 是指定值。

Supplementary information补充资料

I hardly changed, but I changed database to postgresql from db.sqlite3.我几乎没有改变,但我将数据库从 db.sqlite3 更改为 postgresql。

Is this relevant.这是否相关。

this cause was probably db.这个原因可能是分贝。 upload was success, but call of image was not success.上传成功,但图像调用不成功。 when I use ".filter()", image was called descending order at db.sqlite3, but image was not called descending order at postgresql.当我使用“.filter()”时,图像在 db.sqlite3 被称为降序,但图像在 postgresql 未被称为降序。 I need to use ".filter().order('id')".我需要使用“.filter().order('id')”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM