Hi,
I got a bunch of different images of different types ( bmp, gif, png,
tiff etc ) and I want to convert them all to JPEGs using PIL. Is this
possible? When I try I get all sorts of errors, doing something like :
im = Image.open(srcImage) # might be png, gif etc, for instance
test1.png
im.thumbnail(size, Image.ANTIALIAS) # size is 640x480
im.save(targetName, "JPEG") # targetname is test1.jpg
produces an exception. Any clues?
Best regards,
Thomas 2 17016
Thomas wrote: im = Image.open(srcImage) # might be png, gif etc, for instance test1.png im.thumbnail(size, Image.ANTIALIAS) # size is 640x480 im.save(targetName, "JPEG") # targetname is test1.jpg
produces an exception. Any clues?
The problem is that test1.png is a paletted image, and JPEGs can only
hold true-color images. Try changing the last line to:
im.convert('RGB').save(targetName, 'JPEG')
"Thomas" <20**@weholt.org> wrote: I got a bunch of different images of different types ( bmp, gif, png, tiff etc ) and I want to convert them all to JPEGs using PIL. Is this possible? When I try I get all sorts of errors, doing something like :
im = Image.open(srcImage) # might be png, gif etc, for instance test1.png im.thumbnail(size, Image.ANTIALIAS) # size is 640x480 im.save(targetName, "JPEG") # targetname is test1.jpg
produces an exception. Any clues?
the exception contains a pretty strong clue:
"IOError: cannot write mode P as JPEG"
adding
if im.mode != "RGB":
im = im.convert("RGB")
between the open and thumbnail calls fixes this.
</F> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dalan |
last post by:
At first I was not certain what could cause Access 97 from displaying
most jpeg images, but not all. After further testing, it seemed that
all original images of less than 275 pixels per inch or...
|
by: jock |
last post by:
Hello,
Is it possible to perform basic image manipulation through C? I'd like
to upload images through a web interface and resize them so they are
limited to a max height/width restriction.
...
|
by: Jessie |
last post by:
I heard a tool named any2icon. What's your favorite?
|
by: Kenneth Keeley |
last post by:
Hi,
I am creating a news and events page on my Intranet site and I wish to
allow people to upload an image with there news to my site. The text and
image are all stored in an SQL database. I have...
|
by: Dennis |
last post by:
I am trying to convert a bitmap to a JPEG MemoryStream and return a Byte
array containing the resulting JPEG Image as follows:
Public Function BmpToJPEG(ByVal BitMapIn As Bitmap, ByVal Quality As...
|
by: Anitha |
last post by:
Hi All,
How to retrieve images stored in Access database.
I am storing images(jpeg) as OleObject.
I want display them on my web page.
I am unable to do so.Please help me I am using C#
The code...
|
by: Beginner |
last post by:
How do I convert JPEG images to binary files in ASP.NET? Please advice.
Thanks.
|
by: Just D. |
last post by:
All,
Does anybody know some library to resize/convert images on the fly? I'm
especially interested in JPG/GIF/TIF images. Also maybe BMP, but not
critical. Are we having some kind of a standard,...
|
by: mndprasad |
last post by:
hi all
i am doing a project in java where i need to convert 10 jpeg images into a single tiff image..conversion of single jpeg image to single tiff is happening but embedding all the 10 jpeg images...
|
by: wilson |
last post by:
hi
i converted some P5 type .pgm images to .jpg using
x=Image.open("oldimage.pgm")
imsz=x.size
newimg=Image.new('L',imsz)
newimg.putdata(x.getdata())
newimg.save("newimg.jpg")
when i again...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |