PIL: Image.draft -- what are the modes that I can use?

A

abcd

I have PIL 1.1.5 on python 2.4.1 and I am attempting to get a smaller
(file size) of an image.

for example:
im = ImageGrab.grab()

im.save("tmp.gif") ---- about 1.7mb
im.save("tmp.jpeg") ---- about 290kb

anyways I want to save the image as a GIF, but not have it be so
large....so I thought that the Image.draft method would be what I
wanted....

im.draft(mode, size)

Configures the image file loader so it returns a version of the image
that as closely as possible matches the given mode and size. For
example, you can use this method to convert a colour JPEG to greyscale
while loading it, or to extract a 128x192 version from a PCD file.

......what 'modes' can I use? or is there another way to shrink the
size of the image (other than resizing it)?

thanks
 
F

Fredrik Lundh

abcd said:
I have PIL 1.1.5 on python 2.4.1 and I am attempting to get a smaller
(file size) of an image.

for example:
im = ImageGrab.grab()

im.save("tmp.gif") ---- about 1.7mb
im.save("tmp.jpeg") ---- about 290kb

anyways I want to save the image as a GIF, but not have it be so
large....so I thought that the Image.draft method would be what I
wanted....

GIF is horribly unsuitable for screenshots on modern machines. have you
considered using PNG ?

or even better, Flash?

here's a tool that lets you use VNC to capture the screen, and then convert
the result to a flash animation:

http://www.unixuser.org/~euske/vnc2swf/
im.draft(mode, size)

Configures the image file loader so it returns a version of the image
that as closely as possible matches the given mode and size. For
example, you can use this method to convert a colour JPEG to greyscale
while loading it, or to extract a 128x192 version from a PCD file.

note the use of the words "loader" and "loading". draft is used to speed things
up when loading images, not compress things when storing them.

</F>
 
A

abcd

Fredrik said:
GIF is horribly unsuitable for screenshots on modern machines. have you
considered using PNG ?

or even better, Flash?

well I am trying to take screenshots and make them into an animated
GIF, however, putting them into a Flash movie would be cool....any idea
how to go about doing either with python? (windows, possibly linux
later)
 
A

abcd

oh and vnc2swf would not be an option, i cant be setting up a vnc
server, etc. just need to use python (and necessary packages).

animated gif would probably be best i am assuming.
 
F

Fredrik Lundh

abcd said:
well I am trying to take screenshots and make them into an animated
GIF, however, putting them into a Flash movie would be cool....any idea
how to go about doing either with python? (windows, possibly linux
later)

to repeat myself:

here's a tool that lets you use VNC to capture the screen, and then convert
the result to a flash animation:

http://www.unixuser.org/~euske/vnc2swf/

</F>
 
A

abcd

Fredrik said:
to repeat myself:

here's a tool that lets you use VNC to capture the screen, and then convert
the result to a flash animation:

http://www.unixuser.org/~euske/vnc2swf/

</F>

is there a way to make animated GIFs with python? vnc2swf is to much
for what i was hoping. i have no problem with installing python
packages, but having to use VNC is a bit much.

thanks.
 
A

abcd

fredrik,
in other posts you have mentioned the use of gifmaker. i have tried
that with the following:

I am using gifmaker.py from PIL v1.1.5 on python 2.4.1.

CODE
----------------------------------------------------------------
import ImageGrab, gifmaker

seq = []

while keepOnGoing:
im = ImageGrab.grab()
seq.append(im)

fp = open("out.gif", "wb")
gifmaker.makedelta(fp, seq)
fp.close()

---------------------------------------------------------------

however I am getting this error:

Exception in thread Thread-3:
Traceback (most recent call last):
File "c:\Python24\lib\threading.py", line 442, in __bootstrap
self.run()
File "c:\foo.py", line 10, in run
gifmaker.makedelta(fp, seq)
File "c:\gifmaker.py", line 79, in makedelta
for s in getheader(im) + getdata(im):
File "c:\Python24\Lib\site-packages\PIL\GifImagePlugin.py", line 383,
in getdata
ImageFile._save(im, fp, [("gif", (0,0)+im.size, 0,
RAWMODE[im.mode])])
KeyError: 'RGB'

Any ideas? Basically I want to make an animated GIF out of a bunch of
images taken using the ImageGrab module.
 
B

Brett Hoerner

abcd said:

Are you sure you can't use VNC? An animated GIF based on full-screen
grabs will be amazingly huge and have very low color quality at the
same time.

Installing VNC on Windows should take you about 30 seconds, honest.

Or is this for some sort of project where you can't use anything but
CPython software...?

Brett Hoerner
 
A

abcd

Brett said:
Are you sure you can't use VNC? An animated GIF based on full-screen
grabs will be amazingly huge and have very low color quality at the
same time.

Installing VNC on Windows should take you about 30 seconds, honest.

Or is this for some sort of project where you can't use anything but
CPython software...?

Brett Hoerner


the latter.
 
G

Gabriel Genellina

is there a way to make animated GIFs with python? vnc2swf is to much
for what i was hoping. i have no problem with installing python
packages, but having to use VNC is a bit much.

A VNC server is about 400K in size...


--
Gabriel Genellina
Softlab SRL





__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya!
http://www.yahoo.com.ar/respuestas
 
A

abcd

Gabriel said:
A VNC server is about 400K in size...


Yea, VNC is not an option in my case.

thanks anyway, perhaps I'll look into generating a slideshow using
HTML/javascript which can load the images.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top