标签: python-imaging-library

PIL - libjpeg.so.8:无法打开共享对象文件:没有这样的文件或目录

编译libjpeg v8,PIL 1.1.7和导入_imaging在系统Python上工作,但在virtualenv中发出此错误:

libjpeg.so.8: cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)

这是在virtualenv中使用python -v解释器运行的错误

>>> import _imaging
dlopen("/home/ygamretuta/dev/py/django/lib/python2.6/site-packages/PIL/_imaging.so", 2);
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: libjpeg.so.8: cannot open shared object file: No such file or directory
Run Code Online (Sandbox Code Playgroud)

以下是路径:

/home/ygamretuta/dev/py/django/lib/python2.6/site-packages/distribute-0.6.14-py2.6.egg
/home/ygamretuta/dev/py/django/lib/python2.6/site-packages/pip-0.8.1-py2.6.egg
/home/ygamretuta/dev/py/django/lib/python2.6
/home/ygamretuta/dev/py/django/lib/python2.6/plat-linux2
/home/ygamretuta/dev/py/django/lib/python2.6/lib-tk
/home/ygamretuta/dev/py/django/lib/python2.6/lib-old
/home/ygamretuta/dev/py/django/lib/python2.6/lib-dynload
/usr/lib/python2.6
/usr/lib/python2.6/plat-linux2
/usr/lib/python2.6/lib-tk
/home/ygamretuta/dev/py/django/lib/python2.6/site-packages
/home/ygamretuta/dev/py/django/lib/python2.6/site-packages/PIL
Run Code Online (Sandbox Code Playgroud)

我正在使用Ubuntu 10.10,这是uname-a输出:

Linux ygam-desktop 2.6.35-28-generic #49-Ubuntu SMP Tue Mar 1 14:40:58 UTC 2011 i686 GNU/Linux
Run Code Online (Sandbox Code Playgroud)

我使用的是Python 2.6

我已经按照以下指南:

http://appelfreelance.com/2010/06/libjpeg-pil-snow-leopard-python2-6-_jpeg_resync_to_restart/

http://www.jooncode.com/2010/12/02/python-pil-jpeg-resync-restart-error-imaging-module-solve/

http://djangodays.com/2008/09/03/django-imagefield-validation-error-caused-by-incorrect-pil-installation-on-mac/

python django python-imaging-library

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

PIL将带透明度的PNG或GIF转换为JPG而不用

我正在使用PIL1.1.7在Python 2.7中对图像处理器进行原型设计,我希望所有图像都以JPG结尾.输入文件类型将包括透明和没有的tiff,gif,png.我一直在尝试组合两个脚本,我发现1.将其他文件类型转换为JPG和2.通过创建空白图像并将原始图像粘贴到白色背景上来消除透明度.我的搜索是垃圾邮件,人们试图产生或保持透明度,而不是相反.

我正在使用这个:

#!/usr/bin/python
import os, glob
import Image

images = glob.glob("*.png")+glob.glob("*.gif")

for infile in images:
    f, e = os.path.splitext(infile)
    outfile = f + ".jpg"
    if infile != outfile:
        #try:
        im = Image.open(infile)
        # Create a new image with a solid color
        background = Image.new('RGBA', im.size, (255, 255, 255))
        # Paste the image on top of the background
        background.paste(im, im)
        #I suspect that the problem is the line below
        im = background.convert('RGB').convert('P', palette=Image.ADAPTIVE)
        im.save(outfile)
        #except IOError:
           # print "cannot convert", …
Run Code Online (Sandbox Code Playgroud)

python image-processing python-imaging-library

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

PIL:将Bytearray转换为Image

我想验证一个字节组有Image.openImage.verify()没有首先将其写入到磁盘,然后打开它im = Image.open().我查看了.readfrombuffer().readfromstring()方法,但是我需要图像的大小(我只能在将字节流转换为图像时才能获得).

我的Read-Function看起来像这样:

def readimage(path):
    bytes = bytearray()
    count = os.stat(path).st_size / 2
    with open(path, "rb") as f:
        print "file opened"
        bytes = array('h')
        bytes.fromfile(f, count)
    return bytes
Run Code Online (Sandbox Code Playgroud)

然后作为基本测试,我尝试将bytearray转换为图像:

bytes = readimage(path+extension)
im = Image.open(StringIO(bytes))
im.save(savepath)
Run Code Online (Sandbox Code Playgroud)

如果有人知道我做错了什么,或者是否有更优雅的方式将这些字节转换为真正帮助我的图像.

PS:我认为我需要bytearray,因为我对字节进行了操作(故障图像).这确实有效,但我想这样做而不将其写入磁盘,然后再次从磁盘打开图像文件以检查它是否损坏.

编辑:它给我的全部是 IOError: cannot identify image file

python arrays byte image python-imaging-library

17
推荐指数
1
解决办法
4万
查看次数

PIL错误:未安装_imaging C模块

我安装了PIL(Python映像库).

当我运行Python时:

import PIL
import Image
import _imaging
Run Code Online (Sandbox Code Playgroud)

我不会得到错误.但是,在运行我的应用程序时,它会提升

The _imaging C module not installed
Run Code Online (Sandbox Code Playgroud)

python module python-imaging-library

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

使用PIL在python中旋转并将expand参数设置为true时指定图像填充颜色

我正在尝试使用PIL在Python中旋转图像并将expand参数设置为true.似乎当我的图像背景为黑色时,保存为bmp的结果图像将比我的图像具有白色背景要小得多,然后我用白色替换黑色.在任何一种情况下,我的原始图像总是有两种颜色,现在我需要文件大小很小,因为我将这些图像放在嵌入式设备上.

任何想法,如果我可以强制旋转填充另一种颜色扩展或如果有另一种方式旋转我的图片,以使其小?

python image colors rotation python-imaging-library

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

如何在保存前使用PIL调整新上传的图像大小?

我想以800px的高度和宽度调整新图像的大小并保存它们.应用程序不得存储真实图像.有帮助吗?

这是我的代码,它保存原始图像,而不是调整大小的照片:

models.py:

class Photo(models.Model):        
    photo = models.ImageField(upload_to='photos/default/')


    def save(self):

        if not self.id and not self.photo:
            return            

        super(Photo, self).save()

        image = Image.open(self.photo)
        (width, height) = image.size

        "Max width and height 800"        
        if (800 / width < 800 / height):
            factor = 800 / height
        else:
            factor = 800 / width

        size = ( width / factor, height / factor)
        image.resize(size, Image.ANTIALIAS)
        image.save(self.photo.path)
Run Code Online (Sandbox Code Playgroud)

django django-models python-imaging-library

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

PIL - 将GIF帧转换为JPG

我尝试使用Python图像库将gif转换为单个图像,但它会导致奇怪的帧

输入gif是:

来源图片http://longcat.de/gif_example.gif

在我的第一次尝试中,我尝试将Image.new图像转换为RGB图像,其中255,255,255为白色背景 - 就像我在互联网上找到的任何其他示例一样:

def processImage( infile ):

    try:
        im = Image.open( infile )
    except IOError:
        print "Cant load", infile
        sys.exit(1)

    i = 0

    try:
        while 1:

            background = Image.new("RGB", im.size, (255, 255, 255))
            background.paste(im)
            background.save('foo'+str(i)+'.jpg', 'JPEG', quality=80)

            i += 1
            im.seek( im.tell() + 1 )

    except EOFError:
        pass # end of sequence
Run Code Online (Sandbox Code Playgroud)

但它导致奇怪的输出文件:

示例#1 http://longcat.de/gif_example1.jpg

我的第二次尝试是,首先在RGBA中转换gif,然后使用其透明蒙版,使透明片变白:

def processImage( infile ):

    try:
        im = Image.open( infile )
    except IOError:
        print "Cant load", infile
        sys.exit(1)

    i = 0

    try: …
Run Code Online (Sandbox Code Playgroud)

python jpeg image-processing gif python-imaging-library

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

调整大小时保留图像的exif数据(创建缩略图)

当我尝试使用PIL调整图像大小(缩略图)时,exif数据会丢失.

我该怎么做才能保留缩略图中的exif数据?当我搜索相同的,得到一些链接,但似乎没有工作.

from PIL import  Image
import StringIO

file_path = '/home/me/img/a.JPG'
im = Image.open( file_path)
THUMB_SIZES = [(512, 512)]
for thumbnail_size in THUMB_SIZES:
    im.thumbnail( thumbnail_size, Image.ANTIALIAS)
    thumbnail_buf_string = StringIO.StringIO()
    im.save('512_' + "a", "JPEG")
Run Code Online (Sandbox Code Playgroud)

原始图像具有exif数据,但图像im(512_a.JPEG)不具有exif数据.

python exif python-imaging-library

16
推荐指数
3
解决办法
8285
查看次数

带有GlobalPalette的images2gif.py出错

尝试将jpgs序列转换为gif时出错.似乎无法弄清楚如何添加调色板,或者这是否是实际问题.能够使用images2gif.py main中的numpy数组加载GIF .

import PIL
from PIL import Image
import StringIO
import images2gif

images = []
for frame in animation1.frames:
    img_data = s3manager.get_file_as_string(frame.s3_filename)
    image = Image.open(StringIO.StringIO(img_data))
    images.append(image)

images2gif.writeGif('lala3.gif', images, duration=0.5, dither=0)  
Run Code Online (Sandbox Code Playgroud)

有了这个,我收到以下错误:

"images2gif.py", line 436, in writeGifToFile
  fp.write(globalPalette)
TypeError: must be string or buffer, not None
Run Code Online (Sandbox Code Playgroud)

不知道如何为这些jpgs指定调色板.文件不清楚,甚至不确定这是不是问题.救命?

python-imaging-library

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

PIL如何根据图像上绘制的文本缩放图像

我试图动态增加图像大小相对于给出的字体和文本draw.text().

Orignal问题是根据名称和用户选择的字体创建签名图像.

这是我的代码

from PIL import (Image, ImageDraw, ImageFont,)

width=20
height=20
selected_font='simply_glomrous.ttf'
font_size=30

img = Image.new('RGBA', (width, height), (255, 255, 255, 0))
draw = ImageDraw.Draw(img)
font = ImageFont.truetype(selected_font, font_size)
draw.text((0,0), "Adil Malik", (0,0,0), font)
img.save('signature.png')
Run Code Online (Sandbox Code Playgroud)

但我仍然在宽度和高度定义相同的图像大小.我们可以根据字体及其大小动态调整图像大小吗?

注意:此问题与此stackoverflow问题相反

python python-imaging-library python-3.x

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