我正在尝试将已调整大小的图像上传到S3:
fp = urllib.urlopen('http:/example.com/test.png')
img = cStringIO.StringIO(fp.read())
im = Image.open(img)
im2 = im.resize((500, 100), Image.NEAREST)
AK = 'xx' # Access Key ID
SK = 'xx' # Secret Access Key
conn = S3Connection(AK,SK)
b = conn.get_bucket('example')
k = Key(b)
k.key = 'example.png'
k.set_contents_from_filename(im2)
Run Code Online (Sandbox Code Playgroud)
但是我收到一个错误:
in set_contents_from_filename
fp = open(filename, 'rb')
TypeError: coercing to Unicode: need string or buffer, instance found
Run Code Online (Sandbox Code Playgroud) 我有两个从PIL图像转换的Numpy数组(3维uint8).
我想查找第一个图像是否包含第二个图像,如果是,请找出匹配所在的第一个图像内左上角像素的坐标.
有没有办法在Numpy中以足够快的方式完成这个,而不是使用(4!非常慢)纯Python循环?
2D示例:
a = numpy.array([
[0, 1, 2, 3],
[4, 5, 6, 7],
[8, 9, 10, 11]
])
b = numpy.array([
[2, 3],
[6, 7]
])
Run Code Online (Sandbox Code Playgroud)
怎么做这样的事情?
position = a.find(b)
Run Code Online (Sandbox Code Playgroud)
position那会是(0, 2).
使用Python Imaging Library PIL如何检测某个图像的所有像素是黑色还是白色?
〜〜更新
条件:不迭代每个像素!
我正在从Coursera学习Python.在本课程中,他们在CodeSkulptor上使用SimpleGUI模块.谁能告诉我如何将SimpleGUI与python 2.7和3.0 shell集成?
python python-imaging-library python-2.7 python-3.x codeskulptor
我尝试使用pip/easy_install安装Pillow时遇到一个奇怪的错误:
cc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -arch i386 -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -arch i386 -pipe -DHAVE_LIBJPEG -DHAVE_LIBZ -DHAVE_LIBTIFF -I/System/Library/Frameworks/Tcl.framework/Versions/8.5/Headers -I/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -I/usr/local/Cellar/freetype/2.5.3/include/freetype2 -I/private/var/folders/c_/r7sp373509jdb6_1xmmzvl9c0000gn/T/pip_build_tills13/Pillow/libImaging -I/System/Library/Frameworks/Python.framework/Versions/2.7/include -I/usr/local/include -I/usr/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _imaging.c -o build/temp.macosx-10.9-intel-2.7/_imaging.o
clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
error: command 'cc' failed with exit status 1 …Run Code Online (Sandbox Code Playgroud) 当我在Windows中编写代码时,此代码可以正常加载字体文件:
ImageFont.truetype(filename='msyhbd.ttf', size=30);
Run Code Online (Sandbox Code Playgroud)
我想字体位置是在Windows注册表中注册的.但是,当我将代码移动到Ubuntu,并将字体文件复制到/ usr/share/fonts /时,代码无法找到该字体:
self.font = core.getfont(font, size, index, encoding)
IOError: cannot open resource
Run Code Online (Sandbox Code Playgroud)
如何在不指定绝对路径的情况下让PIL找到ttf文件?
我收到错误:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-0f6709e38f49> in <module>()
----> 1 from PIL import Image
C:\Anaconda\lib\site-packages\PIL\Image.py in <module>()
61 from PIL import _imaging as core
62 if PILLOW_VERSION != getattr(core, 'PILLOW_VERSION', None):
---> 63 raise ImportError("The _imaging extension was built for another "
64 " version of Pillow or PIL")
65
ImportError: The _imaging extension was built for another version of Pillow or PIL
Run Code Online (Sandbox Code Playgroud)
每当我尝试使用PIL库时.我正在尝试加载和处理一堆.gif文件,而我现在正在尝试的是以下内容:
from PIL import Image
Run Code Online (Sandbox Code Playgroud)
尝试不同的方法,通过scipy:
import scipy.ndimage as spnd
os.chdir('C:\\WeatherSink\\data\\')
spnd.imread('2014-11-03-0645.gif')
Run Code Online (Sandbox Code Playgroud)
失败:
--------------------------------------------------------------------------- …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用PIL将照片分成多个部分.
def crop(Path,input,height,width,i,k,x,y,page):
im = Image.open(input)
imgwidth = im.size[0]
imgheight = im.size[1]
for i in range(0,imgheight-height/2,height-2):
print i
for j in range(0,imgwidth-width/2,width-2):
print j
box = (j, i, j+width, i+height)
a = im.crop(box)
a.save(os.path.join(Path,"PNG","%s" % page,"IMG-%s.png" % k))
k +=1
Run Code Online (Sandbox Code Playgroud)
但它似乎没有起作用.它会分割照片但不是精确的方式(你可以尝试).
如果用户上传图像,并使用PIL调整大小,我会得到一个PIL Image对象.
PIL Image在将文件保存到数据库之前,如何在模板中显示文件?它甚至可以作为图像传递并渲染吗?
我有以下代码,我认为会调整指定路径中的图像但是当我运行它时,没有任何作用,但python不会抛出任何错误,所以我不知道该怎么做.请指教.谢谢.
from PIL import Image
import os, sys
path = ('C:\Users\Maxxie\color\complete')
def resize():
for item in os.listdir(path):
if os.path.isfile(item):
im = Image.open(item)
f, e = os.path.splitext(item)
imResize = im.resize((200,200), Image.ANTIALIAS)
imResize.save(f + ' resized.jpg', 'JPEG', quality=90)
resize()
Run Code Online (Sandbox Code Playgroud) python ×10
image ×3
python-2.7 ×2
amazon-s3 ×1
boto ×1
codeskulptor ×1
crop ×1
django ×1
easy-install ×1
fonts ×1
numpy ×1
pillow ×1
pip ×1
python-3.x ×1
split ×1
ubuntu ×1