标签: pillow

在Mac上安装Pillow时出现Zlib错误

我一直试图在我的Mac上安装模块Pillow(运行全新安装的El Capitan和python 3.5)已经有一段时间了.使用pip3安装Pillow,我收到一个错误,说找不到zlib,然后导致安装中止.我已经安装了Xcode,所以理论上已经安装了zlib,当我用brew pip安装它时仍然无法工作(所以我卸载了).它工作正常,直到它到达这里:

writing Pillow.egg-info/PKG-INFO
writing dependency_links to Pillow.egg-info/dependency_links.txt
writing top-level names to Pillow.egg-info/top_level.txt
warning: manifest_maker: standard file '-c' not found

reading manifest file 'Pillow.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
writing manifest file 'Pillow.egg-info/SOURCES.txt'
copying PIL/OleFileIO-README.md -> build/lib.macosx-10.6-intel-3.5/PIL
running build_ext
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/private/tmp/pip-build-1yfcb2pj/Pillow/setup.py", line 767, in <module>
    zip_safe=not debug_build(),
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/distutils/dist.py", line 974, in run_command
    cmd_obj.run() …
Run Code Online (Sandbox Code Playgroud)

python macos pillow

17
推荐指数
3
解决办法
3837
查看次数

PIL open()方法不能与BytesIO一起使用

出于某种原因,当我尝试从BytesIO蒸汽制作图像时,它无法识别图像.这是我的代码:

from PIL import Image, ImageGrab
from io import BytesIO

i = ImageGrab.grab()
i.resize((1280, 720))
output = BytesIO()
i.save(output, format = "JPEG")
output.flush()
print(isinstance(Image.open(output), Image.Image))
Run Code Online (Sandbox Code Playgroud)

它抛出的错误的堆栈跟踪:

Traceback (most recent call last):
  File "C:/Users/Natecat/PycharmProjects/Python/test.py", line 9, in <module>
    print(isinstance(Image.open(output), Image.Image))
  File "C:\Python27\lib\site-packages\PIL\Image.py", line 2126, in open
    % (filename if filename else fp))
IOError: cannot identify image file <_io.BytesIO object at 0x02394DB0>
Run Code Online (Sandbox Code Playgroud)

我正在使用PIL的Pillow实现.

python python-imaging-library pillow

16
推荐指数
1
解决办法
2万
查看次数

如何使用枕头与Django

我安装了Pillow,现在想在我的Django网站上使用它,以允许通过我的管理页面上传图像.见上一个问题.

我需要在设置文件或其他地方进行哪些更改才能让Django识别Pillow并允许ImageField正确上传图像?

django django-models django-admin python-imaging-library pillow

15
推荐指数
3
解决办法
3万
查看次数

Django/PIL - 在上传图像时保存缩略图版本

这是我的forms.py:

class UploadImageForm(forms.ModelForm):
    class Meta:
        model = UserImages
        fields = ['photo']
Run Code Online (Sandbox Code Playgroud)

这是我的models.py:

class UserImages(models.Model):
    user = models.ForeignKey(User)
    photo = models.ImageField(upload_to=get_file_path)
Run Code Online (Sandbox Code Playgroud)

这是我的看法:

def uploadImageView(request):
    if request.method == 'POST':
        form = UploadImageForm(request.POST, request.FILES)
        if form.is_valid():
            instance = form.save(commit=False)
            instance.user = request.user
            instance.save()
            return redirect('/')
    else:
        form = UploadImageForm()

    return render(request, 'uploadImagePage.html', {'uploadImageForm': form})
Run Code Online (Sandbox Code Playgroud)

但这只会保存正在上传的图像.如何保存图像的缩略图版本以及具有完全相同名称的图像的缩略图版本,除了后面带有"thumbail"字样?

我读过的教程说我可以做

im = Image.open(infile)
im.thumbnail(size, Image.ANTIALIAS)
Run Code Online (Sandbox Code Playgroud)

获取缩略图但在我的情况下,图像甚至还没有保存.

django image thumbnails python-imaging-library pillow

15
推荐指数
3
解决办法
1万
查看次数

图像裁剪工具(Python)

我是一名电影摄影师,他经常裁剪裁剪/调整图像.因为我拍摄胶片,我必须扫描我的底片,并从批量扫描中裁剪出每一帧.我的扫描仪扫描四条带,每条六张图像(每次扫描24帧/作物).

我的一个朋友给我写了一个Python脚本,它根据输入的坐标自动裁剪图像.该脚本运行良好但在导出图像的文件格式中存在问题.

从扫描开始,每帧应该在240 DPI时产生37mb TIFF(当我在Adobe Lightroom中裁剪和导出时).相反,Cropper输出一个13mb 72 DPI TIFF.

当我运行Cropper时,终端(我在Mac上)警告我"减压炸弹".我的朋友很难过,建议我问Stack Overflow.

我没有Python经验.我可以提供他编写的代码和终端给我的命令.

思考?这将是非常感激和巨大的节省时间.谢谢!

ERROR MESSAGE: /Library/Python/2.7/site-packages/PIL/Image.py:2192: DecompressionBombWarning: Image size (208560540 pixels) exceeds limit of 89478485 pixels, could be decompression bomb DOS attack.
Run Code Online (Sandbox Code Playgroud)

python tiff image python-imaging-library pillow

15
推荐指数
2
解决办法
6116
查看次数

将图像保存为字节并上传到boto3返回内容-MD5不匹配

我正在尝试从s3中提取图像,量化它/操纵它,然后将其存储回s3而不将任何内容保存到磁盘(完全在内存中).我曾经做过一次,但是在返回代码并再次尝试它之后就没用了.代码如下:

import boto3
import io
from PIL import Image

client = boto3.client('s3',aws_access_key_id='',
        aws_secret_access_key='')
cur_image = client.get_object(Bucket='mybucket',Key='2016-03-19 19.15.40.jpg')['Body'].read()

loaded_image = Image.open(io.BytesIO(cur_image))
quantized_image = loaded_image.quantize(colors=50)
saved_quantized_image = io.BytesIO()
quantized_image.save(saved_quantized_image,'PNG')
client.put_object(ACL='public-read',Body=saved_quantized_image,Key='testimage.png',Bucket='mybucket')
Run Code Online (Sandbox Code Playgroud)

我收到的错误是:

botocore.exceptions.ClientError: An error occurred (BadDigest) when calling the PutObject operation: The Content-MD5 you specified did not match what we received.
Run Code Online (Sandbox Code Playgroud)

如果我只是拉一个图像然后把它放回去而不操纵它,它工作正常.我不太确定这里发生了什么.

amazon-s3 python-imaging-library python-3.x pillow boto3

15
推荐指数
2
解决办法
7839
查看次数

Python Pillow不在OSX下安装

我正在尝试安装Python Pillow库,我收到以下错误:

ValueError: zlib is required unless explicitly disabled using --disable-zlib, aborting
Run Code Online (Sandbox Code Playgroud)

我跟着线程尝试修复它:在Linux中安装Pillow(Python模块)时失败

问题是它似乎仍然无法找到我通过自制软件安装的zlib.

我检查了它是否已安装:

> brew search zlib
homebrew/dupes/zlib ?                                        lzlib
Run Code Online (Sandbox Code Playgroud)

我注意到它与标准brew安装位置不同("homebrew/dupes/zlib").我尝试进行卸载/重新安装,然后将其放回到同一个地方("homebrew/dupes/zlib").问题似乎是安装程序/编译器在该位置找不到它.

我的问题是,有没有办法为lib路径设置别名,将安装程序指向此lib位置,或者将其从home-brew中彻底清除,以便像zlib一样重新安装它?最好的路线是什么?

谢谢,RB

python macos homebrew python-imaging-library pillow

14
推荐指数
3
解决办法
5366
查看次数

Python/PIL仿射变换

这是PIL中的一个基本转换问题.在过去的几年里,我已经尝试了至少几次来正确实现这一点,而且似乎在PIL中我没有完全了解Image.transform.我想实现相似变换(或仿射变换),我可以清楚地说明图像的极限.为了确保我的方法有效,我在Matlab中实现了它.

Matlab实现如下:

im = imread('test.jpg');
y = size(im,1);
x = size(im,2);
angle = 45*3.14/180.0;
xextremes = [rot_x(angle,0,0),rot_x(angle,0,y-1),rot_x(angle,x-1,0),rot_x(angle,x-1,y-1)];
yextremes = [rot_y(angle,0,0),rot_y(angle,0,y-1),rot_y(angle,x-1,0),rot_y(angle,x-1,y-1)];
m = [cos(angle) sin(angle) -min(xextremes); -sin(angle) cos(angle) -min(yextremes); 0 0 1];
tform = maketform('affine',m')
round( [max(xextremes)-min(xextremes), max(yextremes)-min(yextremes)])
im = imtransform(im,tform,'bilinear','Size',round([max(xextremes)-min(xextremes), max(yextremes)-min(yextremes)]));
imwrite(im,'output.jpg');

function y = rot_x(angle,ptx,pty),
    y = cos(angle)*ptx + sin(angle)*pty

function y = rot_y(angle,ptx,pty),
    y = -sin(angle)*ptx + cos(angle)*pty
Run Code Online (Sandbox Code Playgroud)

这按预期工作.这是输入:

在此输入图像描述

这是输出:

在此输入图像描述

这是实现相同转换的Python/PIL代码:

import Image
import math

def rot_x(angle,ptx,pty):
    return math.cos(angle)*ptx + math.sin(angle)*pty

def rot_y(angle,ptx,pty):
    return -math.sin(angle)*ptx + math.cos(angle)*pty

angle …
Run Code Online (Sandbox Code Playgroud)

python matlab transformation python-imaging-library pillow

13
推荐指数
2
解决办法
9596
查看次数

ImportError:没有名为Image的模块,ImportError:没有名为PIL的模块--Python,Anaconda,PIL,pillow,mac 10.10.3,

我正在使用Mac OS x 10.10.3 Yosemite和Python 2.7.9 | Anaconda 2.2.0(x86_64)来处理很多python的东西.我正在使用eclipse和谷歌应用引擎.

我已经没有堆栈溢出帖子来读取很多人都有的这个错误,然后通过某种方式解决这个问题对我来说不起作用.

我收到这个错误:

import Image ImportError:没有名为Image的模块

从这段代码:

try:
    from PIL import Image
except:
    import Image
Run Code Online (Sandbox Code Playgroud)

在我尝试了以下之后:

conda install pillow
sudo pip install pillow
pip install pillow
pip install pil
Run Code Online (Sandbox Code Playgroud)

一些堆栈溢出帖子建议查看该路径是否适用于其他用户,所以我在终端中尝试了这个:

python
Python 2.7.9 |Anaconda 2.2.0 (x86_64)| (default, Dec 15 2014, 10:37:34) 
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org …
Run Code Online (Sandbox Code Playgroud)

macos python-imaging-library python-2.7 pillow anaconda

13
推荐指数
2
解决办法
5万
查看次数

PIL:ValueError:未知重采样过滤器,如何调整Flask上传的图像大小?

我正在使用Flask创建一个Web应用程序,我想调整上传的图像大小.我正在使用PIL执行此操作,但会引发错误.

这样做的过程就像这样,但似乎效率低下:

filename = secure_filename(form.image.data.filename)
form.image.data.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
img = Image.open(os.path.join(app.config['UPLOAD_FOLDER'],filename), 'r')
img = img.resize(300, 300)
img.save(filename, quality=100, optimize=True)
Run Code Online (Sandbox Code Playgroud)

我要做的是在用户上传图像后保存图像,打开新文件,调整大小并再次保存.

我该如何修复错误?

还有一种方法可以使用Python库更有效地执行此操作(不保存未调整大小的文件)吗?

python flask pillow

13
推荐指数
2
解决办法
8385
查看次数