473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Convert all images to JPEG

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
Jul 18 '05 #1
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')
Jul 18 '05 #2
"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>

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
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...
6
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. ...
1
by: Jessie | last post by:
I heard a tool named any2icon. What's your favorite?
2
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...
3
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...
2
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...
4
by: Beginner | last post by:
How do I convert JPEG images to binary files in ASP.NET? Please advice. Thanks.
1
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,...
2
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
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,...
0
Oralloy
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,...
0
tracyyun
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...
0
agi2029
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,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.