color JPEGs

Evgeni V. Belin evb0 at gte.com
Fri Sep 24 11:12:13 EDT 1999


Hi Paul,

=> IOError: cannot write mode P as JPEG

I'd suggest to look at pilconvert.py that comes in the Scripts subdir.
Basically, you can use *drafts* to to convert images before saving in
different format:

>>> import Image
>>> im = Image.open('foo.gif')
>>> im.save('foo.jpg')
...
IOError: cannot write mode P as JPEG
>>> im.draft("RGB", im.size)
>>> im = im.convert("RGB")
>>> im.save('foo.jpg')
>>> 

Hope that helps, 
-Evgeni
------- Forwarded Message

Return-Path: python-list-admin at python.org
Delivery-Date: Fri Sep 24 10:47:55 1999
Received: from newman.gte.com (newman.gte.com [132.197.8.26])
	by kuai.gte.com (8.8.8/8.8.8) with ESMTP id KAA01363
	for <evb0 at kuai.gte.com>; Fri, 24 Sep 1999 10:47:51 -0400 (EDT)
Received: from cliff2.gte.com (cliff2.gte.com [132.197.8.43])
	by newman.gte.com (8.9.1/8.9.1) with ESMTP id KAA11552
	for <evb0 at labs.gte.com>; Fri, 24 Sep 1999 10:47:50 -0400 (EDT)
Received: from relay.gte.com (relay.gte.com [132.197.248.10])
	by cliff2.gte.com (8.9.1/8.9.1) with ESMTP id KAA25962
	for <evb0 at ns.gte.com>; Fri, 24 Sep 1999 10:47:50 -0400 (EDT)
Received: from python.org ([132.151.1.90])
	by relay.gte.com (8.9.1/8.9.1) with ESMTP id KAA09793
	for <evb0 at gte.com>; Fri, 24 Sep 1999 10:47:49 -0400 (EDT)
Received: from python.org (localhost [127.0.0.1])
	by python.org (8.9.1a/8.9.1) with ESMTP id KAA13674;
	Fri, 24 Sep 1999 10:45:53 -0400 (EDT)
From: Paul Barrett <Barrett at STScI.Edu>
Newsgroups: comp.lang.python
Subject: color JPEGs
Date: Fri, 24 Sep 1999 10:17:23 -0400
Organization: Space Telescope Science Institute
Lines: 20
Message-ID: <37EB87F2.87A9A19D at STScI.Edu>
NNTP-Posting-Host: dhcp-042.stsci.edu
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 4.6 [en] (X11; I; Linux 2.2.12 i586)
X-Accept-Language: en
Path: news!uunet!ffx.uu.net!pulsar.dimensional.com!dimensional.com!coop.net!ncar!noao!stsci.edu!not-for-mail
Xref: news comp.lang.python:72687
To: python-list at python.org
Sender: python-list-admin at python.org
Errors-To: python-list-admin at python.org
X-Mailman-Version: 1.0.2
Precedence: bulk
List-Id: General discussion list for the Python programming language <python-list.python.org>
X-BeenThere: python-list at python.org

I'm trying to create a color JPEG from Numeric data.  I used Rob Hooft's
message from earlier this year to get me started.  All of his code
appears to work fine.  The problem appears when I try to save the image,
i.e. img.save('filename.jpg'). I get  the following error message:

IOError: cannot write mode P as JPEG

Can a PIL guru tell me what I'm doing wrong and how to proceed? I've
attached the relevant python code to help.

img = Image.Palette('P', (data.shape[1], data.shape[0]),
data.tostring(), 'raw', 'P')
img.palette = ImagePalette.raw('RGB', string.join(palette, ''))
img.save('filename')

- -- Paul





- -- 
http://www.python.org/mailman/listinfo/python-list

------- End of Forwarded Message





More information about the Python-list mailing list