Simple Question, avoid Image.save

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Simple Question, avoid Image.save

auto11436877
Hi, I wanted to get the actual bmp data without writting the content to disk.

Example:
im = Image.new("RGB", (16, 16) )
im.save('image.bmp')

I want to avoid im.save, and just get the actual BMP file data for further processing.

Hope you can help me.

Thanks a lot!
Sean

_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: Simple Question, avoid Image.save

Dan Halbert

On Thursday, December 29, 2011 7:31am, [hidden email] said:

Hi, I wanted to get the actual bmp data without writting the content to disk.

Example:
im = Image.new("RGB", (16, 16) )
im.save('image.bmp')
I want to avoid im.save, and just get the actual BMP file data for further processing.
Do you mean you want to get at the pixels? See Image.getdata() and putdata(), Image.getpixel() and putpixel(), and Image.load()  (fastest way), all of which provide pixel-level access in varying ways.
Dan

_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: Simple Question, avoid Image.save

Matthew Westcott
In reply to this post by auto11436877
On 29 Dec 2011, at 12:31, [hidden email] wrote:

> Hi, I wanted to get the actual bmp data without writting the content to disk.
>
> Example:
> im = Image.new("RGB", (16, 16) )
> im.save('image.bmp')
>
> I want to avoid im.save, and just get the actual BMP file data for further processing.
>
> Hope you can help me.

Hi,
The im.save method can accept a file object instead of a filename, which means you can avoid writing to disk by passing it a StringIO object instead:

import StringIO, Image
im = Image.new("RGB", (16, 16) )
io = StringIO.StringIO()
im.save(io, 'bmp')
bmpdata = io.getvalue()


- Matt
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: Simple Question, avoid Image.save

Edward Cannon
In reply to this post by auto11436877
you want to use Image.save with a file object rather than a file. This
allows you to keep the data in memory without creating a file. There
are several options for file objects, depending on what you might want
to do afterwards.

On Thu, Dec 29, 2011 at 4:31 AM,  <[hidden email]> wrote:

> Hi, I wanted to get the actual bmp data without writting the content to
> disk.
>
> Example:
> im = Image.new("RGB", (16, 16) )
> im.save('image.bmp')
>
> I want to avoid im.save, and just get the actual BMP file data for further
> processing.
>
> Hope you can help me.
>
> Thanks a lot!
> Sean
>
> _______________________________________________
> Image-SIG maillist  -  [hidden email]
> http://mail.python.org/mailman/listinfo/image-sig
>
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: Simple Question, avoid Image.save

Matt Westcott
In reply to this post by auto11436877
On 29 Dec 2011, at 12:31, [hidden email] wrote:

> Hi, I wanted to get the actual bmp data without writting the content to disk.
>
> Example:
> im = Image.new("RGB", (16, 16) )
> im.save('image.bmp')
>
> I want to avoid im.save, and just get the actual BMP file data for further processing.
>
> Hope you can help me.

Hi,
The im.save method can accept a file object instead of a filename, which means you can avoid writing to disk by passing it a StringIO object instead:

import StringIO, Image
im = Image.new("RGB", (16, 16) )
io = StringIO.StringIO()
im.save(io, 'bmp')
bmpdata = io.getvalue()


- Matt
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig
Reply | Threaded
Open this post in threaded view
|

Re: Simple Question, avoid Image.save

Elias Fotinis-2
In reply to this post by auto11436877
On Thu, 29 Dec 2011 14:31:05 +0200, <[hidden email]> wrote:

> Hi, I wanted to get the actual bmp data without writting the content
> to disk.
> Example:im = Image.new("RGB", (16, 16) )im.save('image.bmp')
> I want to avoid im.save, and just get the actual BMP file data for
> further processing.

Use im.tostring() to get the data as a string, or im.getdata() to get a sequence of (R,G,B) tuples.
_______________________________________________
Image-SIG maillist  -  [hidden email]
http://mail.python.org/mailman/listinfo/image-sig