Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8637941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:35:58+00:00 2026-06-12T10:35:58+00:00

When trying to do the following in the PIL python library: Image.open(‘Apple.gif’).save(‘Apple.pgm’) the code

  • 0

When trying to do the following in the PIL python library:

Image.open('Apple.gif').save('Apple.pgm')

the code fails with:

  Traceback (most recent call last):
  File "/home/eran/.eclipse/org.eclipse.platform_3.7.0_155965261/plugins/org.python.pydev_2.6.0.2012062818/pysrc/pydevd_comm.py", line 765, in doIt
    result = pydevd_vars.evaluateExpression(self.thread_id, self.frame_id, self.expression, self.doExec)
  File "/home/eran/.eclipse/org.eclipse.platform_3.7.0_155965261/plugins/org.python.pydev_2.6.0.2012062818/pysrc/pydevd_vars.py", line 376, in evaluateExpression
    result = eval(compiled, updated_globals, frame.f_locals)
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 1439, in save
    save_handler(self, fp, filename)
  File "/usr/lib/python2.7/dist-packages/PIL/PpmImagePlugin.py", line 114, in _save
    raise IOError, "cannot write mode %s as PPM" % im.mode
IOError: cannot write mode P as PPM

The code works fine with conversion to BMP, but JPG also fails.
Strange thing is, a different file(JPG to PGM), works ok.

Other format conversion. That is:

Image.open('Apple.gif').save('Apple.bmp')

works.

Any idea why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:36:00+00:00Added an answer on June 12, 2026 at 10:36 am

    You need to convert the image to RGB mode to make this work.

    im = Image.open('Apple.gif')
    im = im.convert('RGB')
    im.save('Apple.pgm')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to open an image using open method of Image of PIL,
I currently am trying the following code: $sql = $db->query(select id,username,fullname from userss ORDER
I am trying the following piece of code in java, but it doesn't seem
I am trying the following code in eclipse: public class A { List<Integer> intList
I am trying the following code to AutoComplete contact details as the user types
I am trying to convert a PIL image into an array using NumPy. I
I am trying following code String s1 = ß.cfg; System.out.println (s.toUpperCase()); output I am
I was trying following code in which I defined copy c'tor explicitly to solve
Trying the following method to open an Arabic URL: String cmd = "cmd.exe /C
I am trying the following code to make a UIButton look Disabled : btnYourButton.alpha

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.