简体   繁体   English

在 python 中打开和保存图像会生成一个空文件

[英]opening and saving image in python makes an empty file

I am just starting to learn python.我刚刚开始学习python。 I am trying to make a program that opens a file, crops it and saves it.我正在尝试制作一个程序来打开一个文件,裁剪它并保存它。 I wrote this:我是这样写的:

from PIL import Image

image = Image.open('boi.jpg')
crop = image.crop((0,0,200,200))
crop.save("boicropped.jpg","JPEG")

This makes an empty file that i can not open:这会生成一个我无法打开的空文件: 剪裁

i am sorry if it is an obvious mistake i am missing...如果这是我遗漏的明显错误,我很抱歉......

I would remove the declaration of crop.我会删除作物的声明。 Encapsulate your cropping of image, and follow with .save.封装您的图像裁剪,然后使用 .save。

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

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