Hi Sage-Devel,

I have a huge 23MB 10000x10000 PNG image (that Tom Boothby made a long
time ago of a modular form), and I want to shrink it.    Loading it in
GIMP on my mac just freezes GIMP, and similar with other programs.  I
don't feel like installing ImageMagick from source right now.  So, I
thought, I'll try PIL (=Python imaging library) since we just added it
to Sage-4.2.  Here's what happened:

  1.  It was incredibly easy to figure out how to use PIL based on
http://www.pythonware.com/library/pil/handbook/introduction.htm

  2. I loaded my image and tried to resize it, but Sage died with "The
_imaging C module is not installed".
This was because I had Macports (hence libjpeg) installed when I
upgraded Sage, but not anymore, so I reinstalled PIL.  This is
basically the same problem Georg Weber pointed out, which I thought
wouldn't be a big deal.  I'm amazed it bit me the very first time I
tried to actually use PIL.

  3. I typed time a.thumbnail((1000,1000)), wand was happy to see that
it thumbnailed my massive image in only a few seconds!  Very nice.

  4. However, a.save('foo.png') fails with "TypeError: unsupported
operand type(s) for &: 'sage.rings.rational.Rational' and 'int'".

  5. I try again from scratch with a.thumbnail((int(1000),int(1000)))
to force plane Python ints.  This works:

sage: import Image
sage: a = Image.open('huge.png')
sage: time a.thumbnail((int(1000),int(1000)))
CPU times: user 5.54 s, sys: 0.47 s, total: 6.01 s
Wall time: 6.25 s
sage: a.save('smaller.png')
sage: !ls -lh smaller.png
-rw-r--r--  1 wstein  staff   618K Oct 25 10:03 smaller.png

So... it's awesome that we have PIL in Sage!  But we are going to have
to do some polish (possibly patches), just like with Numpy, so that it
plays well with Sage datatypes.

I hope other people will try PIL and provide feedback in this thread.
-- 
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to