By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,986 Members | 1,568 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,986 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Oct 18 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
"abcd" wrote:
>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>

Oct 18 '06 #2

P: n/a
Fredrik Lundh wrote:
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)

Oct 18 '06 #3

P: n/a
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.

Oct 18 '06 #4

P: n/a
"abcd" wrote:
>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)
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>

Oct 18 '06 #5

P: n/a
Fredrik Lundh wrote:
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.

Oct 18 '06 #6

P: n/a
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.

Oct 18 '06 #7

P: n/a
abcd wrote:
...
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

Oct 18 '06 #8

P: n/a
Brett Hoerner wrote:
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.

Oct 18 '06 #9

P: n/a
At Wednesday 18/10/2006 11:26, abcd wrote:
>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

Oct 18 '06 #10

P: n/a
Gabriel Genellina wrote:
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.

Oct 19 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.