SVG PIL decoder

2009-09-30 Thread Patrick Sabin
I would like to open svg files with PIL, but svg doesn't seem to be 
supported. Does anyone know about a svg decoder for the PIL?


- Patrick
--
http://mail.python.org/mailman/listinfo/python-list


Re: [Image-SIG] Some issue with easy_install and PIL/Imaging

2009-09-30 Thread Chris Withers

Fredrik Lundh wrote:

On Fri, Sep 11, 2009 at 3:49 PM, Chris Withers ch...@simplistix.co.uk wrote:

Klein Stéphane wrote:

Resume :
1. first question : why PIL package in pypi don't work ?

Because Fred Lundh have his package distributions unfortunate names that
setuptools doesn't like...


It used to support this, but no longer does.  To me, that says more
about the state of setuptools than it does about the state of PIL,
which has been using the same naming convention for 15 years.


Yep, but it is now in the minority, and consistency in package naming is 
always good.


Would there be any problems for you in naming the distribution in a 
setuptools-friendly way from the next point release?


cheers,

Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Re: SVG PIL decoder

2009-09-30 Thread Donn
On Wednesday 30 September 2009 18:01:50 Patrick Sabin wrote:
 I would like to open svg files with PIL, but svg doesn't seem to be
 supported. Does anyone know about a svg decoder for the PIL?
Have a look at Cairo (python-cairo) in conjunction with librsvg (python-rsvg) 
-- that'll fix you up. You can go from an SVG to a PNG/array and thence into 
PIL if you need to.

\d
-- 
home: http://otherwise.relics.co.za/
2D vector animation : https://savannah.nongnu.org/projects/things/
Font manager : https://savannah.nongnu.org/projects/fontypython/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SVG PIL decoder

2009-09-30 Thread Patrick Sabin

Donn wrote:
Have a look at Cairo (python-cairo) in conjunction with librsvg (python-rsvg) 
-- that'll fix you up. You can go from an SVG to a PNG/array and thence into 
PIL if you need to.


Thanks for the tip. Got it work, although it was a bit tricky, as 
resizing doesn't seem to be supported by python-rsvg and 
cairo.ImageSurface.create_from_png doesn't allow StringIO or 
TemporaryFile for some reason (got Memory Error). So the code, if 
someone else needs it or someone can improve it:


def open_svg_as_image(fn, width, height):
tmpfd, tmppath = tempfile.mkstemp(.png)
tmpfile = os.fdopen(tmpfd,'w')

file = StringIO.StringIO()
svgsurface = cairo.SVGSurface (file, width, height)
svgctx = cairo.Context(svgsurface)
svg = rsvg.Handle(file=fn)
svgwidth = svg.get_property('width')
svgheight = svg.get_property('height')
svgctx.scale(width/float(svgwidth),height/float(svgheight))
svg.render_cairo(svgctx)

svgsurface.write_to_png(tmpfile)
tmpfile.close()
svgsurface.finish()

tmpfile = open(tmppath, 'r')
imgsurface = cairo.ImageSurface.create_from_png(tmpfile)
imgwidth = imgsurface.get_width()
imgheight = imgsurface.get_height()

data = imgsurface.get_data()

im = Image.frombuffer(RGBA,(imgwidth, imgheight),
data ,raw,RGBA,0,1)
os.remove(tmppath)
return im

--
http://mail.python.org/mailman/listinfo/python-list


Re: SVG PIL decoder

2009-09-30 Thread Donn
On Thursday 01 October 2009 01:08:28 Patrick Sabin wrote:
 Thanks for the tip. Got it work, although it was a bit tricky, as
 resizing doesn't seem to be supported by python-rsvg and
 cairo.ImageSurface.create_from_png doesn't allow StringIO or
My best suggestions are to visit the Cairo website -- inside there somewhere 
is a recipe page with many samples in Python. 

Next would be  http://www.tortall.net/mu/wiki/CairoTutorial. 

Third is a tutorial I made (perhaps less useful) on my site 
http://otherwise.relics.co.za/wiki/Tuts/Python/Cairo/ links at bottom of that 
page

Fourth is to join the ca...@cairographics.org mailing list at 
http://lists.cairographics.org/mailman/listinfo/cairo they are super helpful.

Lastly is my animation API (in sig)which is also Python and may help you with 
the source.

The general idea for scaling is to use matrices (cairo provides all commands) 
and then output the surface to a file-like object.

My animation API brings selected snippets of SVG in from an Inkscape file 
(tagged by id), animates them by tweening and can output each frame to another 
SVG or to a PNG.

HTH,
\d
-- 
home: http://otherwise.relics.co.za/
2D vector animation : https://savannah.nongnu.org/projects/things/
Font manager : https://savannah.nongnu.org/projects/fontypython/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Image-SIG] Some issue with easy_install and PIL/Imaging

2009-09-28 Thread Fredrik Lundh
On Fri, Sep 11, 2009 at 3:49 PM, Chris Withers ch...@simplistix.co.uk wrote:
 Klein Stéphane wrote:

 Resume :
 1. first question : why PIL package in pypi don't work ?

 Because Fred Lundh have his package distributions unfortunate names that
 setuptools doesn't like...

It used to support this, but no longer does.  To me, that says more
about the state of setuptools than it does about the state of PIL,
which has been using the same naming convention for 15 years.

/F
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Some issue with easy_install and PIL/Imaging

2009-09-28 Thread Klein Stéphane

Fredrik Lundh a écrit :

On Fri, Sep 11, 2009 at 3:49 PM, Chris Withers ch...@simplistix.co.uk wrote:

Klein Stéphane wrote:

Resume :
1. first question : why PIL package in pypi don't work ?

Because Fred Lundh have his package distributions unfortunate names that
setuptools doesn't like...


It used to support this, but no longer does.  To me, that says more
about the state of setuptools than it does about the state of PIL,
which has been using the same naming convention for 15 years.


Ok, and what can we do ?

Is a setuptools issue ?

Can distribute (http://bitbucket.org/tarek/distribute/wiki/Home setuptools 
fork) fix this issue easily ?

Regards,
Stephane
--
http://mail.python.org/mailman/listinfo/python-list


Re: Some issue with easy_install and PIL/Imaging

2009-09-11 Thread Chris Withers

Klein Stéphane wrote:

Resume :
1. first question : why PIL package in pypi don't work ?


Because Fred Lundh have his package distributions unfortunate names that 
setuptools doesn't like...



2. second question : when I add PIL dependence in my setup.py and I do
   python setup.py develop, I've this error :
   error: Could not find required distribution Imaging.
   Why ?


See above.


Now, I add --find-links parameter to easy_install :


If you google harder, you'll find there are packagings of PIL that do 
work with setuptools...


Chris

--
Simplistix - Content Management, Batch Processing  Python Consulting
   - http://www.simplistix.co.uk
--
http://mail.python.org/mailman/listinfo/python-list


Some issue with easy_install and PIL/Imaging

2009-09-09 Thread Klein Stéphane

Hi,

I would like to insert Imaging dependence in my setup.py file.

Resume :
1. first question : why PIL package in pypi don't work ?
2. second question : when I add PIL dependence in my setup.py and I do
   python setup.py develop, I've this error :
   error: Could not find required distribution Imaging.
   Why ?


Full explication :

First, I test manualy installation :

::

(env1)skl...@eee-sklein:$ easy_install pil
Searching for pil
Reading http://pypi.python.org/simple/pil/
Reading http://www.pythonware.com/products/pil
Reading http://effbot.org/zone/pil-changes-115.htm
Reading http://effbot.org/downloads/#Imaging
No local packages or download links found for pil
error: Could not find suitable distribution for 
Requirement.parse('pil')


This command fail !

Now, I try with Imaging package name :

::

(env1)skl...@eee-sklein:$ easy_install Imaging
Searching for Imaging
Reading http://pypi.python.org/simple/Imaging/
Couldn't find index page for 'Imaging' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://pypi.python.org/simple/
No local packages or download links found for Imaging
error: Could not find suitable distribution for 
Requirement.parse('Imaging')


This command fail also.

Now, I add --find-links parameter to easy_install :

::

(env1)skl...@eee-sklein:$ easy_install --find-links 
http://www.pythonware.com/products/pil/ Imaging

Searching for Imaging
Reading http://www.pythonware.com/products/pil/
Best match: Imaging 1.1.6
Downloading http://effbot.org/downloads/Imaging-1.1.6.tar.gz
Processing Imaging-1.1.6.tar.gz
Running Imaging-1.1.6/setup.py -q bdist_egg --dist-dir 
/tmp/easy_install-rF1PG1/Imaging-1.1.6/egg-dist-tmp-Xtv8GV
libImaging/Effects.c:210: attention : ‘perlin_init’ defined but not 
used

libImaging/File.c: In function ‘ImagingOpenPPM’:
libImaging/File.c:112: attention : ignoring return value of 
‘fread’, declared with attribute warn_unused_result
libImaging/File.c:119: attention : ignoring return value of 
‘fread’, declared with attribute warn_unused_result
libImaging/Geometry.c:236: attention : ‘quadratic_transform’ 
defined but not used

libImaging/Quant.c:311: attention : ‘test_sorted’ defined but not used
libImaging/Quant.c:676: attention : ‘checkContained’ defined but 
not used
libImaging/QuantHash.c:136: attention : ‘_hashtable_test’ defined 
but not used


PIL 1.1.6 BUILD SUMMARY

version   1.1.6
platform  linux2 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
  [GCC 4.3.3]

*** TKINTER support not available (Tcl/Tk 8.5 libraries needed)
--- JPEG support ok
--- ZLIB (PNG/ZIP) support ok
--- FREETYPE2 support ok

To add a missing option, make sure you have the required
library, and set the corresponding ROOT variable in the
setup.py script.

To check the build, run the selftest.py script.
zip_safe flag not set; analyzing archive contents...
Image: module references __file__
Adding PIL 1.1.6 to easy-install.pth file
Installing pilprint.py script to 
/home/sklein/tests/test_eggs_pil/env1/bin
Installing pilfile.py script to 
/home/sklein/tests/test_eggs_pil/env1/bin
Installing pilconvert.py script to 
/home/sklein/tests/test_eggs_pil/env1/bin
Installing pilfont.py script to 
/home/sklein/tests/test_eggs_pil/env1/bin
Installing pildriver.py script to 
/home/sklein/tests/test_eggs_pil/env1/bin


Installed 
/home/sklein/tests/test_eggs_pil/env1/lib/python2.6/site-packages/PIL-1.1.6-py2.6-linux-i686.egg

Skipping dependencies for PIL 1.1.6

This command work very well.

First question : why PIL package in pypi don't work ?

Now, I remove PIL in my virtualenv to test setup.py installation :

::

(env1)skl...@eee-sklein:$ rm 
/home/sklein/tests/test_eggs_pil/env1/lib/python2.6/site-packages/PIL-1.1.6-py2.6-linux-i686.egg/ 
-rf


(env1)skl...@eee-sklein:$ cat setup.py
from setuptools import setup, find_packages
import sys, os

version = '0.0'

setup(name='test_pil',
  version=version,
  description=,
  long_description=\
,
  classifiers=[], # Get strings from 
http://pypi.python.org/pypi?%3Aaction=list_classifiers

  keywords='',
  author='',
  author_email='',
  url='',
  license='',
  packages=find_packages(exclude=['ez_setup', 'examples', 
'tests']),

  include_package_data=True,
  zip_safe=False,
  dependency_links=['http://www.pythonware.com/products/pil/'],
  install_requires

Re: PIL and Python

2009-08-22 Thread catafest
If I make it work, i will send the solution. Thank you !

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL and Python

2009-08-21 Thread catafest
I don't extract data from jpegs.
I wanna put some data in this (copyright of my site) ...

On Aug 20, 2:01 pm, MaxTheMouse maxthemo...@googlemail.com wrote:
 On Aug 20, 10:23 am, catafest catalinf...@gmail.com wrote:

  On my photo jpg i have this :

  Image Type: jpeg (The JPEG image format)
  Width: 1224 pixels
  Height: 1632 pixels
  Camera Brand: Sony Ericsson
  Camera Model: W810i
  Date Taken: 2009:07:09 08:16:21
  Exposure Time: 1/19 sec.
  ISO Speed Rating: 320
  Flash Fired: Flash did not fire, compulsory flash mode.
  Metering Mode: Center-Weighted Average
  Software: R4EA031     prgCXC1250321_ORANGE_HN 4.5

  This is the data i want edit it to make some copyright for my site.

 I don't know about PIL but you might want to try 
 exif.py.http://sourceforge.net/projects/exif-py/

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL and Python

2009-08-21 Thread Michele Petrazzo
catafest wrote:
 I don't extract data from jpegs. I wanna put some data in this
 (copyright of my site) ...
 

My wrap for freeimage, called freeimagepy :) can't, as now, wrote exif
information on the image, but since freeimage can do it, I think that
it's not so difficult to add this type of feature.
If you have some time for investigate and create a patch, I'll be happy
to include it into the mainline!

Contact me directly if you want to talk of need some help on how do it.

Michele
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL and Python

2009-08-20 Thread catafest

On my photo jpg i have this :

Image Type: jpeg (The JPEG image format)
Width: 1224 pixels
Height: 1632 pixels
Camera Brand: Sony Ericsson
Camera Model: W810i
Date Taken: 2009:07:09 08:16:21
Exposure Time: 1/19 sec.
ISO Speed Rating: 320
Flash Fired: Flash did not fire, compulsory flash mode.
Metering Mode: Center-Weighted Average
Software: R4EA031 prgCXC1250321_ORANGE_HN 4.5

This is the data i want edit it to make some copyright for my site.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL and Python

2009-08-20 Thread MaxTheMouse
On Aug 20, 10:23 am, catafest catalinf...@gmail.com wrote:
 On my photo jpg i have this :

 Image Type: jpeg (The JPEG image format)
 Width: 1224 pixels
 Height: 1632 pixels
 Camera Brand: Sony Ericsson
 Camera Model: W810i
 Date Taken: 2009:07:09 08:16:21
 Exposure Time: 1/19 sec.
 ISO Speed Rating: 320
 Flash Fired: Flash did not fire, compulsory flash mode.
 Metering Mode: Center-Weighted Average
 Software: R4EA031     prgCXC1250321_ORANGE_HN 4.5

 This is the data i want edit it to make some copyright for my site.

I don't know about PIL but you might want to try exif.py.
http://sourceforge.net/projects/exif-py/
-- 
http://mail.python.org/mailman/listinfo/python-list


PIL and Python

2009-08-13 Thread catalinf...@gmail.com
Hello !
I want use python to change the note from .jpeg files .
What is the functions on PIL how make this ?
Thank you !
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL and Python

2009-08-13 Thread Martin
On Aug 13, 1:55 pm, catalinf...@gmail.com catalinf...@gmail.com
wrote:
 Hello !
 I want use python to change the note from .jpeg files .
 What is the functions on PIL how make this ?
 Thank you !

What do u mean by the note?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL and Python

2009-08-13 Thread Nobody
On Thu, 13 Aug 2009 16:38:07 -0700, Martin wrote:

 I want use python to change the note from .jpeg files .
 What is the functions on PIL how make this ?
 
 What do u mean by the note?

I think he means the EXIF data.

-- 
http://mail.python.org/mailman/listinfo/python-list


Freetype2 in PIL

2009-07-24 Thread moerchendiser2k3
Hi,

I have a problem with Freetype2 in the Python Image Library. I
compiled it as 64bit and I got a file named freetype239.lib. So I
added this file to a folder called lib. I added the parent folder of
the lib folder to the setup.py settings (like all the others: libjpeg,
zlib). LIbjpeg and Zlib works fine on Windows 64 bit and the installer
can find them.

But I just get a Freetype2 not found. Even renaming it to
freetype.lib and freetype2.lib doesnt work.


Any suggestions why PIL cant find the library?

Bye and thanks in advance :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Freetype2 in PIL

2009-07-24 Thread moerchendiser2k3
Hi,

I have a problem with Freetype2 in the Python Image Library. I
compiled it as 64bit and I got a file named freetype239.lib. So I
added this file to a folder called lib. I added the parent folder of
the lib folder to the setup.py settings (like all the others: libjpeg,
zlib). LIbjpeg and Zlib works fine on Windows 64 bit and the installer
can find them.

But I just get a Freetype2 not found. Even renaming it to
freetype.lib and freetype2.lib doesnt work.


Any suggestions why PIL cant find the library?

Bye and thanks in advance :)
-- 
http://mail.python.org/mailman/listinfo/python-list


raster (PIL)

2009-07-23 Thread superpollo

hi.

i wrote a program which transforms a string of zeroes ando ones into a 
png file.


#!/usr/bin/env python
import Image
import sys
bits_in_a_byte = 8
raster_string = \

0010010000101000
00100100101010100100
00001110001010100100
00100100101010100100
0010010000000000


0010
10101001
1010
10101000
00001000


raster_lines = raster_string.splitlines()
high = len(raster_lines)
wide = len(raster_lines[0])
bytes_in_a_row = wide/bits_in_a_byte
bitmap = 
for raster_line in raster_lines:
for byte_count in range(bytes_in_a_row):
first_bit = byte_count*bits_in_a_byte
bitmap += 
chr(int(raster_line[first_bit:first_bit+bits_in_a_byte] , 2))

im = Image.fromstring(1, (wide , high) , bitmap)
im.save(sys.stdout , PNG)

any suggestions for improvement?

bye
--
http://mail.python.org/mailman/listinfo/python-list


Re: raster (PIL)

2009-07-23 Thread Diez B. Roggisch
superpollo wrote:

 hi.
 
 i wrote a program which transforms a string of zeroes ando ones into a
 png file.
 
 #!/usr/bin/env python
 import Image
 import sys
 bits_in_a_byte = 8
 raster_string = \
 
 0010010000101000
 00100100101010100100
 00001110001010100100
 00100100101010100100
 0010010000000000
 
 
 0010
 10101001
 1010
 10101000
 00001000
 
 
 raster_lines = raster_string.splitlines()
 high = len(raster_lines)
 wide = len(raster_lines[0])
 bytes_in_a_row = wide/bits_in_a_byte

This will give you the wrong result if not divideable by bits_in_a_byte. 

 bitmap = 
 for raster_line in raster_lines:
  for byte_count in range(bytes_in_a_row):
  first_bit = byte_count*bits_in_a_byte
  bitmap +=
 chr(int(raster_line[first_bit:first_bit+bits_in_a_byte] , 2))
 im = Image.fromstring(1, (wide , high) , bitmap)
 im.save(sys.stdout , PNG)
 
 any suggestions for improvement?

Instead of 

res = 
for ...:
res += ...

use 

res = []
for ...:
res.append(...)

.join(res)

There are some optimizations for the +=-op on strings, but I'm not sure how
far they go, and the other form is safer.

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: raster (PIL)

2009-07-23 Thread Peter Otten
superpollo wrote:

 i wrote a program which transforms a string of zeroes ando ones into a
 png file.
 
 #!/usr/bin/env python
 import Image
 import sys
 bits_in_a_byte = 8
 raster_string = \
 
 0010010000101000
 00100100101010100100
 00001110001010100100
 00100100101010100100
 0010010000000000
 
 
 0010
 10101001
 1010
 10101000
 00001000
 
 
 raster_lines = raster_string.splitlines()
 high = len(raster_lines)
 wide = len(raster_lines[0])
 bytes_in_a_row = wide/bits_in_a_byte
 bitmap = 
 for raster_line in raster_lines:
  for byte_count in range(bytes_in_a_row):
  first_bit = byte_count*bits_in_a_byte
  bitmap +=
 chr(int(raster_line[first_bit:first_bit+bits_in_a_byte] , 2))
 im = Image.fromstring(1, (wide , high) , bitmap)
 im.save(sys.stdout , PNG)
 
 any suggestions for improvement?

You can simplify the inner loop:

for first_bit in range(0, wide, bits_in_a_byte):
bitmap += ...

and get rid of a few helper variables.

Here's a different approach:

#!/usr/bin/env python
import Image
import string
import sys

mapping = string.maketrans(01, \x00\xff)

raster_string = ...

width = raster_string.index(\n)
height = raster_string.count(\n)

raster_string = raster_string.translate(mapping, \n)

im = Image.fromstring(L, (width, height), raster_string)
im.convert(1).save(sys.stdout, PNG)

The idea is to move the bit-twiddling from python to code written in C, 
pointless for such a tiny picture but crucial for the performance when you 
want to manipulate larger images.

Peter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: raster (PIL)

2009-07-23 Thread superpollo

Diez B. Roggisch wrote:

superpollo wrote:

...

high = len(raster_lines)
wide = len(raster_lines[0])
bytes_in_a_row = wide/bits_in_a_byte



This will give you the wrong result if not divideable by bits_in_a_byte. 



then maybe:

#!/usr/bin/env python
import Image
import sys
bits_in_a_byte = 8
raster_string = \
00
0010010000101000
00100100101010100100
00001110001010100100
00100100101010100100
0010010000000000


0010
10101001
1010
10101000
00001000


raster_lines = raster_string.splitlines()
high = len(raster_lines)
wide = len(raster_lines[0])
bytes_in_a_row = wide/bits_in_a_byte
wide_for_real = bytes_in_a_row*bits_in_a_byte
if wide_for_real:
bitmap = 
for raster_line in raster_lines:
for byte_count in range(bytes_in_a_row):
first_bit = byte_count*bits_in_a_byte
bitmap += 
chr(int(raster_line[first_bit:first_bit+bits_in_a_byte] ,

2))
im = Image.fromstring(1, (wide_for_real , high) , bitmap)
im.save(sys.stdout , PNG)

bye
--
http://mail.python.org/mailman/listinfo/python-list


Re: raster (PIL)

2009-07-23 Thread superpollo

Peter Otten wrote:

superpollo wrote:



i wrote a program which transforms a string of zeroes ando ones into a
png file.

...

any suggestions for improvement?

...

Here's a different approach:

...
The idea is to move the bit-twiddling from python to code written in C, 
pointless for such a tiny picture but crucial for the performance when you 
want to manipulate larger images.


very very interesting... you know i come from a lower level language 
approach (C/Pascal) so i find it difficult (but full of fascination) to 
adapt to such a different and much simpler way of thinking.


anyways, thanks a lot.

bye

--
http://mail.python.org/mailman/listinfo/python-list


Re: raster (PIL)

2009-07-23 Thread superpollo

Peter Otten wrote:
...

Here's a different approach:

...

raster_string = ...

width = raster_string.index(\n)
height = raster_string.count(\n)


your approach has a funny side-effect: try to remove just one zero from 
the first line of the raster ;-)


bye
--
http://mail.python.org/mailman/listinfo/python-list


Re: raster (PIL)

2009-07-23 Thread superpollo

Peter Otten wrote:
...

im.convert(1).save(sys.stdout, PNG)

...

a q about pil:

im.convert(1)

is different from:

im2 = im.convert(1)

right?

in the former im is changed (the method applies to im) but in the latter 
im is unchanged (first im is copied unto im2 and then the method is 
applied to im2)... am i right?


bye
--
http://mail.python.org/mailman/listinfo/python-list


Re: raster (PIL)

2009-07-23 Thread Diez B. Roggisch
superpollo wrote:

 Diez B. Roggisch wrote:
 superpollo wrote:
 ...
high = len(raster_lines)
wide = len(raster_lines[0])
bytes_in_a_row = wide/bits_in_a_byte
 
 
 This will give you the wrong result if not divideable by bits_in_a_byte.
 
 
 then maybe:
 
 #!/usr/bin/env python
 import Image
 import sys
 bits_in_a_byte = 8
 raster_string = \
 00
 0010010000101000
 00100100101010100100
 00001110001010100100
 00100100101010100100
 0010010000000000
 
 
 0010
 10101001
 1010
 10101000
 00001000
 
 
 raster_lines = raster_string.splitlines()
 high = len(raster_lines)
 wide = len(raster_lines[0])
 bytes_in_a_row = wide/bits_in_a_byte
 wide_for_real = bytes_in_a_row*bits_in_a_byte

No. Because that would skip up to 7 bits.

Instead, do

bytes_in_a_row = wide/bits_in_a_byte
if wide % bits_in_a_byte:
   bytes_in_a_row += 1

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: raster (PIL)

2009-07-23 Thread Peter Otten
superpollo wrote:

 Peter Otten wrote:
 ...
 im.convert(1).save(sys.stdout, PNG)
 ...
 
 a q about pil:
 
 im.convert(1)
 
 is different from:
 
 im2 = im.convert(1)
 
 right?
 
 in the former im is changed (the method applies to im) but in the latter
 im is unchanged (first im is copied unto im2 and then the method is
 applied to im2)... am i right?

No. A method has no clue whether its result is used or discarded. Therefore

im.convert(1)

creates a new image in the specified mode, too, which is discarded 
immediately. If you don't need the result you probably shouldn't call the 
method at all.

Peter


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: raster (PIL)

2009-07-23 Thread superpollo

Peter Otten wrote:

superpollo wrote:



Peter Otten wrote:
...


im.convert(1).save(sys.stdout, PNG)


...

a q about pil:

im.convert(1)

is different from:

im2 = im.convert(1)

right?

in the former im is changed (the method applies to im) but in the latter
im is unchanged (first im is copied unto im2 and then the method is
applied to im2)... am i right?



No. A method has no clue whether its result is used or discarded. Therefore

im.convert(1)

creates a new image in the specified mode, too, which is discarded 
immediately.


but in:

im.convert(1).save(sys.stdout, PNG)

the new (anonymous) image created by .convert is not discarded 
*immediately*, i mean *before* the .save method is called on it, right?


bye
--
http://mail.python.org/mailman/listinfo/python-list


Re: raster (PIL)

2009-07-23 Thread Peter Otten
superpollo wrote:

 Peter Otten wrote:
 superpollo wrote:
 
 
Peter Otten wrote:
...

im.convert(1).save(sys.stdout, PNG)

...

a q about pil:

im.convert(1)

is different from:

im2 = im.convert(1)

right?

in the former im is changed (the method applies to im) but in the latter
im is unchanged (first im is copied unto im2 and then the method is
applied to im2)... am i right?
 
 
 No. A method has no clue whether its result is used or discarded.
 Therefore
 
 im.convert(1)
 
 creates a new image in the specified mode, too, which is discarded
 immediately.
 
 but in:
 
 im.convert(1).save(sys.stdout, PNG)
 
 the new (anonymous) image created by .convert is not discarded
 *immediately*, i mean *before* the .save method is called on it, right?

Of course. Think of it as a shortcut for

tmp = im.convert(...)
tmp.save(...)
del tmp

Peter


-- 
http://mail.python.org/mailman/listinfo/python-list


PIL for OSX 64bit

2009-07-21 Thread moerchendiser2k3
Hi,

I have a problem with Python and the Python Image Library to get it
work on OSX 64 bit. Maybe anyone can help me? I started Python in 64
bit mode and called Image.open(...).load() and got:

ImportError: The _imaging C module is not installed

Yes, it seems PIL is not available in 64 bit on my system, but I can't
compile it in any way. Is there a tutorial or something like that
which explains how I can compile it in 64 bit? I found a workaround
where I added this function to the setup.py

OrigExtension = Extension
def Extension(*args, **kwargs):
extra_args = ['-arch', 'x86_64']
kwargs['extra_compile_args'] = extra_args + kwargs.get
('extra_compile_args', [])
kwargs['extra_link_args'] = extra_args + kwargs.get('extra_link_args',
[])
return OrigExtension(*args, **kwargs)

without success. Can anyone help me? Thanks...


Cheers, Googler
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL for OSX 64bit

2009-07-21 Thread Ned Deily
In article 
e0564f03-f736-4d0f-8c50-e1bce0eb5...@r2g2000yqm.googlegroups.com,
 moerchendiser2k3 googler.1.webmas...@spamgourmet.com wrote:
 I have a problem with Python and the Python Image Library to get it
 work on OSX 64 bit. Maybe anyone can help me? I started Python in 64
 bit mode and called Image.open(...).load() and got:
 
 ImportError: The _imaging C module is not installed
[...]

It's hard to know what your problem is without more information.  One 
potential stumbling block: PIL has dependencies on other open-source 
libraries, such as libjpeg and freetype.  You'll need to have 64-bit 
versions of them available when building and when running, as well.  
There are a number of ways to do that.  The simplest might be to 
download pre-built frameworks containing those libraries from here:

http://www.kyngchaos.com/software:frameworks

There are also build scripts there for building your own versions from 
scratch.

-- 
 Ned Deily,
 n...@acm.org

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PIL Python Imaging Library

2009-06-08 Thread Tim Harig
On 2009-06-08, Xah Lee xah...@gmail.com wrote:
 is there a python image library that does pretty much what imagemagick
 does?

http://www.pythonware.com/products/pil/
-- 
http://mail.python.org/mailman/listinfo/python-list


Building PIL under Cygwin Python 2.5

2009-05-28 Thread Erik Johnson
This has apparently been a problematic thing for a while now, as the
following article indicates.  I first ran into the error message about
not being able to remap C:\cygwin\bin\tk84.dll to be the same address
as it's parent.

Using that information, Google helped me find this article:
http://blog.datahammer.info/2008/11/install-pil-under-cygwin-python-25.html

After following it's advice and running:
$ ./rebase -b 0x10 tk84.dll

I was able to get the PIL build to proceed, but when it was done, it
said that there was no support built for Tk, and I then noticed that
basic Tkinter functionality was broken from the Python interpreter.

I went back to Cygwin setup, and had it reinstall the tcl/tk package,
and then Tkinter (import from the interactive interp.) got fixed.

Googling some more, I found this article (which implied datahammer
isn't quite right):  http://www.pythonchallenge.com/forums/viewtopic.php?t=135

I ran /usr/bin/rebaseall (from ash)(and if you end up doing this
yourself, be aware that it takes a while - I was afraid that process
had hung and I was going to have to rebuild the whole Cygwin shooting
match from scratch, but it eventually completed (silently)).

After this, I checked that Tkinter still worked from Python (it did),
and then tore out the whole PIL directory (Imaging-1.1.6) I had tried
to install from before, re-extracted the tar file to get a clean
install directory, and then again attempted to build PIL.  Now,
instead of getting the failure message about not being able to remap
the dll, the build just hangs:

$ python setup.py build_ext -i
running build_ext
building '_imaging' extension
creating build
creating build/temp.cygwin-1.5.25-i686-2.5
creating build/temp.cygwin-1.5.25-i686-2.5/libImaging
gcc -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-
prototypes -DHAVE_LIBJPEG -DHAVE_LIBZ -I/usr/include/freetype2 -
IlibImaging -I/usr/include -I/home/ej/python/PIL/jpeg-6b -I/usr/
include/python2.5 -c _imaging.c -o build/temp.cygwin-1.5.25-i686-2.5/
_imaging.o

eventually hit CTRL-C to leave

Now, I'm rather stuck and I'm thinking This really shouldn't be that
hard.

So, rebasing (rebaseall'ing) the cygwin system as outlined in the
datahammer blog entry (along with the ash advice of the pychallenge
article) still doesn't seem to be enough to get a clean build.

I think this is an issue that probably needs to be addressed by PIL
maintainers that fully understand the root of the problem (and it
should probably go in the PIL FAQ), but in the meantime does anyone
out there know how to get around this issue?

Thanks,
-ej
-- 
http://mail.python.org/mailman/listinfo/python-list


PIL, and Parts of tuples

2009-04-13 Thread Vistro
I have two problems, and I can't find anything about either of them.
The first is that PIL does not seem to have any way to search each and every
pixel for a value, like

for pixel in img:
if pixel = ((60, 30), (58, 23), (87 57)):
# Get out of the for loop
# Also, save the pixel quardinates to a variable


Then, I also want it to look at a specific pixel (I've got that down), and
do something if the any one of the values in the tuple is out of range.

The issue is, the range is different for every value. Basically, it is to
see if the pixel is in an acceptable color range. So, say, the 60 above can
be anywhere from 58-62, but the 30 needs to be between 28-40.

Is there any way to parse/deal with a value at a specific slot in a tuple?
--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL, and Parts of tuples

2009-04-13 Thread Chris Rebert
On Mon, Apr 13, 2009 at 1:34 PM, Vistro vis...@vistro.net wrote:
 I have two problems, and I can't find anything about either of them.
 The first is that PIL does not seem to have any way to search each and every
 pixel for a value, like
 for pixel in img:
     if pixel = ((60, 30), (58, 23), (87 57)):
snip
 see if the pixel is in an acceptable color range. So, say, the 60 above can
 be anywhere from 58-62, but the 30 needs to be between 28-40.
 Is there any way to parse/deal with a value at a specific slot in a tuple?

Yes, use subscripting, just like with lists:

the_tuple = (60, 30)#for example

if not (58 = the_tuple[0] = 62) or not (28 = the_tuple[1] = 40):
#it's out of range, do something

Cheers,
Chris
-- 
I have a blog:
http://blog.rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL, and Parts of tuples

2009-04-13 Thread Vistro
Actually, I screwed up.
See 60, 30? That's actually the range. The tuple to be checked will look
like

(40, 25, 51)

So yeah. Sorry for the bad info.

For a good time, go to Start:Run and type in format Chttp://www.vistro.net/

On Mon, Apr 13, 2009 at 3:41 PM, Chris Rebert c...@rebertia.com wrote:

 On Mon, Apr 13, 2009 at 1:34 PM, Vistro vis...@vistro.net wrote:
  I have two problems, and I can't find anything about either of them.
  The first is that PIL does not seem to have any way to search each and
 every
  pixel for a value, like
  for pixel in img:
  if pixel = ((60, 30), (58, 23), (87 57)):
 snip
  see if the pixel is in an acceptable color range. So, say, the 60 above
 can
  be anywhere from 58-62, but the 30 needs to be between 28-40.
  Is there any way to parse/deal with a value at a specific slot in a
 tuple?

 Yes, use subscripting, just like with lists:

 the_tuple = (60, 30)#for example

 if not (58 = the_tuple[0] = 62) or not (28 = the_tuple[1] = 40):
#it's out of range, do something

 Cheers,
 Chris
 --
 I have a blog:
 http://blog.rebertia.com

--
http://mail.python.org/mailman/listinfo/python-list


Writing a Raw Image to a File (Win, PIL)

2009-04-11 Thread W. eWatson

I have an image of described as:
Img Info:  {}
 size:  (640, 480)
 format:  None
 mode:  P
 palette:  ImagePalette.ImagePalette instance at 0x02393378
 bands:  ('P',)
 type:  type 'instance'

I'd like to write it to a file. Apparently, I need to convert it to a string 
first. How do I do that? Pickle?

--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet



--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing a Raw Image to a File (Win, PIL)

2009-04-11 Thread Diez B. Roggisch

W. eWatson schrieb:

I have an image of described as:
Img Info:  {}
 size:  (640, 480)
 format:  None
 mode:  P
 palette:  ImagePalette.ImagePalette instance at 0x02393378
 bands:  ('P',)
 type:  type 'instance'

I'd like to write it to a file. Apparently, I need to convert it to a 
string first. How do I do that? Pickle?


Did you bother reading the PIL documentation just for about 30seconds?

http://www.pythonware.com/library/pil/handbook/image.htm

Hint: look for save.

Diez
--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing a Raw Image to a File (Win, PIL)

2009-04-11 Thread W. eWatson

Diez B. Roggisch wrote:

W. eWatson schrieb:

I have an image of described as:
Img Info:  {}
 size:  (640, 480)
 format:  None
 mode:  P
 palette:  ImagePalette.ImagePalette instance at 0x02393378
 bands:  ('P',)
 type:  type 'instance'

I'd like to write it to a file. Apparently, I need to convert it to a 
string first. How do I do that? Pickle?


Did you bother reading the PIL documentation just for about 30seconds?

http://www.pythonware.com/library/pil/handbook/image.htm

Hint: look for save.

Diez
So, you are telling me what? To save it as a jpg file, or maybe a bmp file? 
All of them have headers, right?


--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

Web Page: www.speckledwithstars.net/

--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing a Raw Image to a File (Win, PIL)

2009-04-11 Thread MRAB

W. eWatson wrote:

I have an image of described as:
Img Info:  {}
 size:  (640, 480)
 format:  None
 mode:  P
 palette:  ImagePalette.ImagePalette instance at 0x02393378
 bands:  ('P',)
 type:  type 'instance'

I'd like to write it to a file. Apparently, I need to convert it to a 
string first. How do I do that? Pickle?


Have you tried the .tostring() method?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing a Raw Image to a File (Win, PIL)

2009-04-11 Thread W. eWatson

MRAB wrote:

W. eWatson wrote:

I have an image of described as:
Img Info:  {}
 size:  (640, 480)
 format:  None
 mode:  P
 palette:  ImagePalette.ImagePalette instance at 0x02393378
 bands:  ('P',)
 type:  type 'instance'

I'd like to write it to a file. Apparently, I need to convert it to a 
string first. How do I do that? Pickle?


Have you tried the .tostring() method?
Perfect. Works exactly like I had hoped, 640x480 bytes--nothing more. 
Thanks. I had noticed it, but didn't get the connection. Then I wandered 
around nearby in the PIL description, and noticed something about decoding 
and write. Unknown territory to me. However, if I had followed up there was 
a connection between tostring and raw decoding.


--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

Web Page: www.speckledwithstars.net/

--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing a Raw Image to a File (Win, PIL)

2009-04-11 Thread Diez B. Roggisch

W. eWatson schrieb:

Diez B. Roggisch wrote:

W. eWatson schrieb:

I have an image of described as:
Img Info:  {}
 size:  (640, 480)
 format:  None
 mode:  P
 palette:  ImagePalette.ImagePalette instance at 0x02393378
 bands:  ('P',)
 type:  type 'instance'

I'd like to write it to a file. Apparently, I need to convert it to a 
string first. How do I do that? Pickle?


Did you bother reading the PIL documentation just for about 30seconds?

http://www.pythonware.com/library/pil/handbook/image.htm

Hint: look for save.

Diez
So, you are telling me what? To save it as a jpg file, or maybe a bmp 
file? All of them have headers, right?


Yes. Where exactly do you say I don't want headers, I want raw data 
dumped to the disk?


Diez
--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing a Raw Image to a File (Win, PIL)

2009-04-11 Thread MRAB

Diez B. Roggisch wrote:

W. eWatson schrieb:

Diez B. Roggisch wrote:

W. eWatson schrieb:

I have an image of described as:
Img Info:  {}
 size:  (640, 480)
 format:  None
 mode:  P
 palette:  ImagePalette.ImagePalette instance at 0x02393378
 bands:  ('P',)
 type:  type 'instance'

I'd like to write it to a file. Apparently, I need to convert it to 
a string first. How do I do that? Pickle?


Did you bother reading the PIL documentation just for about 30seconds?

http://www.pythonware.com/library/pil/handbook/image.htm

Hint: look for save.

Diez
So, you are telling me what? To save it as a jpg file, or maybe a bmp 
file? All of them have headers, right?


Yes. Where exactly do you say I don't want headers, I want raw data 
dumped to the disk?



Erm, in the Subject line? :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Writing a Raw Image to a File (Win, PIL)

2009-04-11 Thread Diez B. Roggisch

MRAB schrieb:

Diez B. Roggisch wrote:

W. eWatson schrieb:

Diez B. Roggisch wrote:

W. eWatson schrieb:

I have an image of described as:
Img Info:  {}
 size:  (640, 480)
 format:  None
 mode:  P
 palette:  ImagePalette.ImagePalette instance at 0x02393378
 bands:  ('P',)
 type:  type 'instance'

I'd like to write it to a file. Apparently, I need to convert it to 
a string first. How do I do that? Pickle?


Did you bother reading the PIL documentation just for about 30seconds?

http://www.pythonware.com/library/pil/handbook/image.htm

Hint: look for save.

Diez
So, you are telling me what? To save it as a jpg file, or maybe a bmp 
file? All of them have headers, right?


Yes. Where exactly do you say I don't want headers, I want raw data 
dumped to the disk?



Erm, in the Subject line? :-)


Darn. Should consider reading them.

Diez
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with PIL/Tkinter Program Example

2009-04-09 Thread Peter Otten
W. eWatson wrote:

 Something is amiss here. The program produces a canvas in which one can
 move an object around. The input file is hard coded (see open). If you
 want to try it, you'll need to provide a file. Python error below. Name
 space difficulty?

 Traceback (most recent call last):
File
 C
\Sandia_Meteors\Sentinel_Development\Development_Sentuser-Utilities\Playground\fun-move_object.py,
 line 45, in module
  Demo(root)
File
 C
\Sandia_Meteors\Sentinel_Development\Development_Sentuser-Utilities\Playground\fun-move_object.py,
 line 35, in Demo
  data.img=ImageTk.PhotoImage(img)
 NameError: global name 'ImageTk' is not defined

If you want to use the ImageTk module you have to import it first:

 #Mouse movement
 from Tkinter import *
 import PIL
 import Image

  import ImageTk

[rest of your code here]

Peter
--
http://mail.python.org/mailman/listinfo/python-list


Problem with PIL/Tkinter Program Example

2009-04-09 Thread W. eWatson



Something is amiss here. The program produces a canvas in which one can move 
an object around. The input file is hard coded (see open). If you want to 
try it, you'll need to provide a file. Python error below. Name space 
difficulty?


#Mouse movement
from Tkinter import *
import PIL
import Image


class data:
startx=0
starty=0

def startmotioncallback(event):
data.startx=event.x
data.starty=event.y


def motioncallback(event):
deltax=event.x-data.startx
deltay=event.y-data.starty
data.startx=event.x
data.starty=event.y
# should put some limits on where the cirle is moved
# left as exercise.
data.cnv.move(data.ring,deltax,deltay)

def Demo(root):
# resize window
root.geometry('400x400+0+0')
data.root=root
# make a canvas
cnv=Canvas(root)
cnv.pack(expand=1,fill=BOTH)
data.cnv=cnv
img=Image.open('jupa9810.jpg')  # some image you have.
raw_input(Hello)
data.img=ImageTk.PhotoImage(img)
data.photo=cnv.create_image(0,0,image=data.img,anchor='nw')
data.ring=cnv.create_oval((100,100,300,300))
cnv.bind(B1-Motion,motioncallback)
cnv.bind(Button-1,startmotioncallback)
root.mainloop()

Traceback (most recent call last):
  File 
C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser-Utilities\Playground\fun-move_object.py, 
line 45, in module

Demo(root)
  File 
C:\Sandia_Meteors\Sentinel_Development\Development_Sentuser-Utilities\Playground\fun-move_object.py, 
line 35, in Demo

data.img=ImageTk.PhotoImage(img)
NameError: global name 'ImageTk' is not defined
--
http://mail.python.org/mailman/listinfo/python-list


Re: Problem with PIL/Tkinter Program Example

2009-04-09 Thread W. eWatson

Peter Otten wrote:

W. eWatson wrote:


Something is amiss here. The program produces a canvas in which one can
move an object around. The input file is hard coded (see open). If you
want to try it, you'll need to provide a file. Python error below. Name
space difficulty?



Traceback (most recent call last):
   File
C

\Sandia_Meteors\Sentinel_Development\Development_Sentuser-Utilities\Playground\fun-move_object.py,

line 45, in module
 Demo(root)
   File
C

\Sandia_Meteors\Sentinel_Development\Development_Sentuser-Utilities\Playground\fun-move_object.py,

line 35, in Demo
 data.img=ImageTk.PhotoImage(img)
NameError: global name 'ImageTk' is not defined


If you want to use the ImageTk module you have to import it first:


#Mouse movement
from Tkinter import *
import PIL
import Image


  import ImageTk

[rest of your code here]

Peter

Very good. Thanks.

--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

Web Page: www.speckledwithstars.net/

--
http://mail.python.org/mailman/listinfo/python-list


PIL\Tkinter and Transparencies, Rubber Lines, and Dragging Image Objects

2009-04-07 Thread W. eWatson
Basically, I'd like to know how one (broadly, e.g., references in Win-land) 
does IP (image processing) and drawing techniques such as rubber lines, and 
dragging image objects across the canvas. I know there are some pretty 
powerful toolkits out there, but I'd like to limit this to PIL and Tkinter. 
If it can't be done with them, then I'll consider other possibilities.  As a 
starter, on the topic of transparencies, consider this program that I pulled 
off the web and was posted in 1999. It purports to illustrate how one might 
produce a transparency.


   #!/usr/bin/python
   # see http://mail.python.org/pipermail/python-list/1999-May/003388.html
   from Tkinter import *
   import Image, ImageTk
   import tkFileDialog

   class Transparency:
def __init__(self, parent):
 self.canvas = Canvas(parent, bg='green')
 self.canvas.pack()
 b = Button(parent, command=self.open, text=Select graphics file)
 b.pack()

def open(self):
 self.canvas.delete(ALL)
 filename = tkFileDialog.askopenfilename()
 if filename != '':
  im = Image.open(filename)
  if im.mode != RGBA:
   im = Image.open(filename).convert(RGBA)
   source = im.split()
   R, G, B, A = 0, 1, 2, 3
   mask = im.point(lambda i: i  0 and 255) # use black as transparent
   source[A].paste(mask)
   im = Image.merge(im.mode, source)  # build a new multiband image

  self.graphic = ImageTk.PhotoImage(image=im)
  self.canvas.create_image(100, 100, image=self.graphic)
   if __name__ == __main__:
root = Tk()
test = Transparency(root)
root.mainloop()

It colors the canvas green, and produces a black background. An image is
merged with the background. I tried out the program. It executes, but I
do not see where the transparency is apparent. I used a gif with a
picture of a telescope on a white background, and the result is what I
would see if I pasted the telescope and white background onto the green
canvas.

If there's something missing in my observation, I'd like to know what it is.

To further explore drawing graphics, what roughly is the capability of 
Tkinter or PIL to allow one to place a transparent layer (mode, I guess in 
PIL may be roughly equivalent to a layer in tools like Photoshop) on top of 
an image and then move the transparency around over the image with a mouse?


--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

Web Page: www.speckledwithstars.net/

--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL\Tkinter and Transparencies, Rubber Lines, and Dragging Image Objects

2009-04-07 Thread Eric Brunel
W. eWatson wrote:
 Basically, I'd like to know how one (broadly, e.g., references in Win-land)
 does IP (image processing) and drawing techniques such as rubber lines, and
 dragging image objects across the canvas. I know there are some pretty
 powerful toolkits out there, but I'd like to limit this to PIL and Tkinter.
 If it can't be done with them, then I'll consider other possibilities.  As a
 starter, on the topic of transparencies, consider this program that I pulled
 off the web and was posted in 1999. It purports to illustrate how one might
 produce a transparency.

OK, maybe I'm dumb but:

 #!/usr/bin/python
 # see http://mail.python.org/pipermail/python-list/1999-May/003388.html
 from Tkinter import *
 import Image, ImageTk
 import tkFileDialog

 class Transparency:
  def __init__(self, parent):
   self.canvas = Canvas(parent, bg='green')
   self.canvas.pack()
   b = Button(parent, command=self.open, text=Select graphics file)
   b.pack()

  def open(self):
   self.canvas.delete(ALL)
   filename = tkFileDialog.askopenfilename()
   if filename != '':
im = Image.open(filename)
if im.mode != RGBA:
 im = Image.open(filename).convert(RGBA)
 source = im.split()
 R, G, B, A = 0, 1, 2, 3
 mask = im.point(lambda i: i  0 and 255) # use black as transparent
 

 source[A].paste(mask)
 im = Image.merge(im.mode, source)  # build a new multiband image

self.graphic = ImageTk.PhotoImage(image=im)
self.canvas.create_image(100, 100, image=self.graphic)
 if __name__ == __main__:
  root = Tk()
  test = Transparency(root)
  root.mainloop()

 It colors the canvas green, and produces a black background. An image is
 merged with the background. I tried out the program. It executes, but I
 do not see where the transparency is apparent. I used a gif with a
 picture of a telescope on a white background, and the result is what I
  

 would see if I pasted the telescope and white background onto the green
 canvas.

I have neither PIL, nor the image you're using so I can just guess. But if you
want to use a white background, maybe you should use a mask defined with:

mask = im.point(lambda i: 255 if i = 255 else 0)

(if I understood the mask construction correctly...).

HTH
 - Eric -
--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL\Tkinter and Transparencies, Rubber Lines, and Dragging Image Objects

2009-04-07 Thread W. eWatson
You got it. That lamda did look a little odd. The white background is opaque 
and the telescope is seen as green. The program will ask for a file. I 
didn't write the code.


Eric Brunel wrote:

W. eWatson wrote:

Basically, I'd like to know how one (broadly, e.g., references in Win-land)
does IP (image processing) and drawing techniques such as rubber lines, and
dragging image objects across the canvas. I know there are some pretty
powerful toolkits out there, but I'd like to limit this to PIL and Tkinter.
If it can't be done with them, then I'll consider other possibilities.  As a
starter, on the topic of transparencies, consider this program that I pulled
off the web and was posted in 1999. It purports to illustrate how one might
produce a transparency.


OK, maybe I'm dumb but:


#!/usr/bin/python
# see http://mail.python.org/pipermail/python-list/1999-May/003388.html
from Tkinter import *
import Image, ImageTk

...

HTH
 - Eric -



--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

Web Page: www.speckledwithstars.net/

--
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a PIL image object to a buffer

2009-04-07 Thread Gabriel Genellina
En Wed, 01 Apr 2009 19:20:43 -0300, Simon Hibbs simon.hi...@gmail.com  
escribió:

On 1 Apr, 21:43, Gary Herron gher...@islandtraining.com wrote:

Simon Hibbs wrote:



 I'm trying to dump a snapshot of my application window to the
 clipboard. I can use ImageGrab in PIL to get the screen data into a
 PIL image object, which i have converted to a bitmap using ImageWin,
 but when I try to pass this to the clipboard using -

 win32clipboard.SetClipboardData(win32clipboard.CF_BITMAP, img)

 It fails, telling be that The object must support the buffer
 interface.


The second argument to SetClipboardData should be a handle to a bitmap  
resource, not a string.

See win32\test\test_clipboard.py for an example.

PS: Hmm, looking at SetClipboardData, seems that a string containing the  
data in the right format *might* work too. But it's easier to use  
LoadImage than building the resource by hand, I think.


--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a PIL image object to a buffer

2009-04-02 Thread Diez B. Roggisch

Simon Hibbs schrieb:

On 1 Apr, 21:43, Gary Herron gher...@islandtraining.com wrote:

Simon Hibbs wrote:

I'm trying to dump a snapshot of my application window to the
clipboard. I can use ImageGrab in PIL to get the screen data into a
PIL image object, which i have converted to a bitmap using ImageWin,
but when I try to pass this to the clipboard using -
win32clipboard.SetClipboardData(win32clipboard.CF_BITMAP, img)
It fails, telling be that The object must support the buffer
interface.
How can I convert a PIL image into a buffer object? I can't find any
clues.

PIL images have a tostring method that returns a string containing all
the pixel data.  Would that help you to either create the needed
buffer?  Or perhaps you could by-pass the need for a buffer, and just
use the byte string.


If I use tostring I get a string which I can put on the clipboard, but
it isn't any kind of image. I can make a PIL image from the string but
them I'm back to square one again.


Did you actually try that? Strings support the buffer interface, and the 
type of the binary data you set should be defined by the first argument.


Alternatively (if the string is not of the proper format), maybe storing 
the image to a (c)StringIO-object as BMP and retrieving it's value would 
help.


However, I think your concerns about wasting memory when using a file 
are moot - creating an extra memory buffer isn't less memory consuming, 
and if the file is living only a few seconds it might not even actually 
hit the disk at all. In the end, the important thing is the working 
clipboard.


Diez
--
http://mail.python.org/mailman/listinfo/python-list


PIL Handbooks

2009-04-02 Thread W. eWatson
I'm very new to PIL, and don't see any handbooks for 1.1.6 or the 
forthcoming 1.1.7. In fact, this looks like the extent of them:


* Python Imaging Library Handbook for 1.1.5 (online)
* Python Imaging Library Handbook for 1.1.3 (PDF)

Somewhere in my recent search I see that 1.1.6 has some features like 
digital cameras and scanners. Ah here, 
http://pypi.python.org/pypi/PIL/1.1.6. Any other news?


I'd settle even for a 1.1.5 pdf of the handbook right now.
--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

Web Page: www.speckledwithstars.net/

--
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a PIL image object to a buffer

2009-04-02 Thread Simon Hibbs
On 2 Apr, 08:28, Diez B. Roggisch de...@nospam.web.de wrote:
 Simon Hibbs schrieb:



  On 1 Apr, 21:43, Gary Herron gher...@islandtraining.com wrote:
  Simon Hibbs wrote:
  I'm trying to dump a snapshot of my application window to the
  clipboard. I can use ImageGrab in PIL to get the screen data into a
  PIL image object, which i have converted to a bitmap using ImageWin,
  but when I try to pass this to the clipboard using -
  win32clipboard.SetClipboardData(win32clipboard.CF_BITMAP, img)
  It fails, telling be that The object must support the buffer
  interface.
  How can I convert a PIL image into a buffer object? I can't find any
  clues.
  PIL images have a tostring method that returns a string containing all
  the pixel data.  Would that help you to either create the needed
  buffer?  Or perhaps you could by-pass the need for a buffer, and just
  use the byte string.

  If I use tostring I get a string which I can put on the clipboard, but
  it isn't any kind of image. I can make a PIL image from the string but
  them I'm back to square one again.

 Did you actually try that? Strings support the buffer interface, and the
 type of the binary data you set should be defined by the first argument.

 Alternatively (if the string is not of the proper format), maybe storing
 the image to a (c)StringIO-object as BMP and retrieving it's value would
 help.

 However, I think your concerns about wasting memory when using a file
 are moot - creating an extra memory buffer isn't less memory consuming,
 and if the file is living only a few seconds it might not even actually
 hit the disk at all. In the end, the important thing is the working
 clipboard.

Yes I did try this, the code to dump the sting version to the
clipboard worked, but pasting it back out wasn't possible although I
could print them to the console.

I don't mean wasting memory, just that actualy hitting the file system
and creating a file seems as though it shouldn't be necessery. Is
there any good reason why you can't just create an empty buffer object
or file object directly? It seems like an unecessery restriction,
unless there's some underlying reason such as that it's hard to
implement in c, which seems implausible. Sorry, that's a rhetorical
question.

I've not had a chance to work on this today, if I find an elegant way
round it I'll post the results for future googling.

Simon Hibbs
--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL Handbooks

2009-04-02 Thread Irmen de Jong

W. eWatson wrote:
I'm very new to PIL, and don't see any handbooks for 1.1.6 or the 
forthcoming 1.1.7. In fact, this looks like the extent of them:


* Python Imaging Library Handbook for 1.1.5 (online)
* Python Imaging Library Handbook for 1.1.3 (PDF)

Somewhere in my recent search I see that 1.1.6 has some features like 
digital cameras and scanners. Ah here, 
http://pypi.python.org/pypi/PIL/1.1.6. Any other news?


I'd settle even for a 1.1.5 pdf of the handbook right now.


Download the source package tarball , it contains the HTML documentation.

--irmen
--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL Handbooks

2009-04-02 Thread W. eWatson

Irmen de Jong wrote:

W. eWatson wrote:
I'm very new to PIL, and don't see any handbooks for 1.1.6 or the 
forthcoming 1.1.7. In fact, this looks like the extent of them:


* Python Imaging Library Handbook for 1.1.5 (online)
* Python Imaging Library Handbook for 1.1.3 (PDF)

Somewhere in my recent search I see that 1.1.6 has some features like 
digital cameras and scanners. Ah here, 
http://pypi.python.org/pypi/PIL/1.1.6. Any other news?


I'd settle even for a 1.1.5 pdf of the handbook right now.


Download the source package tarball , it contains the HTML documentation.

--irmen
In the Doc foler, I see a bunch of html files, but nothing about a handbook. 
 It seems like the front sections are missing in that folder. Concepts, 
tutor, whatever.


--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

Web Page: www.speckledwithstars.net/

--
http://mail.python.org/mailman/listinfo/python-list


Default Tkinter Structure of a 640x480 PIL BMP File?

2009-04-01 Thread W. eWatson
See Subject. Does it have a header, DIB,  palette, and data section? What is 
the default depth?

--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

Web Page: www.speckledwithstars.net/

--
http://mail.python.org/mailman/listinfo/python-list


Converting a PIL image object to a buffer

2009-04-01 Thread Simon Hibbs
I'm trying to dump a snapshot of my application window to the
clipboard. I can use ImageGrab in PIL to get the screen data into a
PIL image object, which i have converted to a bitmap using ImageWin,
but when I try to pass this to the clipboard using -

win32clipboard.SetClipboardData(win32clipboard.CF_BITMAP, img)

It fails, telling be that The object must support the buffer
interface.

How can I convert a PIL image into a buffer object? I can't find any
clues.

Help appreciated,

Simon Hibbs


--
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a PIL image object to a buffer

2009-04-01 Thread Gary Herron

Simon Hibbs wrote:

I'm trying to dump a snapshot of my application window to the
clipboard. I can use ImageGrab in PIL to get the screen data into a
PIL image object, which i have converted to a bitmap using ImageWin,
but when I try to pass this to the clipboard using -

win32clipboard.SetClipboardData(win32clipboard.CF_BITMAP, img)

It fails, telling be that The object must support the buffer
interface.

How can I convert a PIL image into a buffer object? I can't find any
clues.
  


PIL images have a tostring method that returns a string containing all 
the pixel data.  Would that help you to either create the needed 
buffer?  Or perhaps you could by-pass the need for a buffer, and just 
use the byte string.


Gary Herron


Help appreciated,

Simon Hibbs


--
http://mail.python.org/mailman/listinfo/python-list
  


--
http://mail.python.org/mailman/listinfo/python-list


Re: Converting a PIL image object to a buffer

2009-04-01 Thread Simon Hibbs
On 1 Apr, 21:43, Gary Herron gher...@islandtraining.com wrote:
 Simon Hibbs wrote:
  I'm trying to dump a snapshot of my application window to the
  clipboard. I can use ImageGrab in PIL to get the screen data into a
  PIL image object, which i have converted to a bitmap using ImageWin,
  but when I try to pass this to the clipboard using -

  win32clipboard.SetClipboardData(win32clipboard.CF_BITMAP, img)

  It fails, telling be that The object must support the buffer
  interface.

  How can I convert a PIL image into a buffer object? I can't find any
  clues.

 PIL images have a tostring method that returns a string containing all
 the pixel data.  Would that help you to either create the needed
 buffer?  Or perhaps you could by-pass the need for a buffer, and just
 use the byte string.

If I use tostring I get a string which I can put on the clipboard, but
it isn't any kind of image. I can make a PIL image from the string but
them I'm back to square one again.

I suppse I could save the image object to a real file and then send
that to the clipboard, but that seems wasteful and I'd have to worry
about what to call it and where to put it. Much neater if I could just
create it in memory somehow.

Simon Hibbs
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Imaging Library (PIL): create PDF from scratch

2009-02-25 Thread zelegolas
Like David said now i used PIL for individual images and reportlab to
generate a pdf.

Thanks for your advices :)

--
http://mail.python.org/mailman/listinfo/python-list


Python Imaging Library (PIL): create PDF from scratch

2009-02-23 Thread zelegolas
Hi,

I have some scan generated by SANE and i would like to do some
transformation (like crop, brightness and resize) and finaly put all
those images in PDF file.

With PIL i can do all the transformations that i want. But i don't
know how i can create from scratch a PDF. I'm not even sure that PIL
is the right library for that.

Any help/informations will be appreciate
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Imaging Library (PIL): create PDF from scratch

2009-02-23 Thread Steve Holden
zelegolas wrote:
 Hi,
 
 I have some scan generated by SANE and i would like to do some
 transformation (like crop, brightness and resize) and finaly put all
 those images in PDF file.
 
 With PIL i can do all the transformations that i want. But i don't
 know how i can create from scratch a PDF. I'm not even sure that PIL
 is the right library for that.
 
PIL is great for graphics, but I use ReportLab's open source stuff (see
www.reportlab.org) for creating PDFs - that's what it was designed for,
and you can easily incorporate your graphics.

regards
 Steve
-- 
Steve Holden+1 571 484 6266   +1 800 494 3119
Holden Web LLC  http://www.holdenweb.com/

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Imaging Library (PIL): create PDF from scratch

2009-02-23 Thread Scott David Daniels

zelegolas wrote:

Hi,

I have some scan generated by SANE and i would like to do some
transformation (like crop, brightness and resize) and finaly put all
those images in PDF file.

With PIL i can do all the transformations that i want. But i don't
know how i can create from scratch a PDF. I'm not even sure that PIL
is the right library for that.

Any help/informations will be appreciate


Use PIL to fiddle the individual images, and reportlab to build
a pdf from the (now tweaked) images.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL install driving me mad! With solution!

2009-02-19 Thread Hendrik van Rooyen
bleah jo...@ph...arizona.edu wrote:


I'm trying to get PIL 1.16 installed on a SUSE SLES10 system, and
cannot, for the life of me, get the thing to compile with jpeg
support.

The libjpeg-devel libraries are installed, and are present in /usr/lib
JUST WHERE SPECIFIED in the setup.py file, and the jpeglib.h incliude
file is present  JUST WHERE SPECIFIED in the setup.py file.

The build process proceeds without errors, yet selftest.py fails with
the error:

tonic:~/html2pdf_sources/Imaging-1.1.6 # python selftest.py
*
Failure in example: _info(Image.open(Images/lena.jpg))

This is the problem.
Lena with the feathered hat is a shy girl,
and she does not allow just anybody 
to look at her.

:-)

- Hendrik

--
http://mail.python.org/mailman/listinfo/python-list


PIL install driving me mad! With solution!

2009-02-18 Thread bleah
I'm trying to get PIL 1.16 installed on a SUSE SLES10 system, and
cannot, for the life of me, get the thing to compile with jpeg
support.

The libjpeg-devel libraries are installed, and are present in /usr/lib
JUST WHERE SPECIFIED in the setup.py file, and the jpeglib.h incliude
file is present  JUST WHERE SPECIFIED in the setup.py file.

The build process proceeds without errors, yet selftest.py fails with
the error:

tonic:~/html2pdf_sources/Imaging-1.1.6 # python selftest.py
*
Failure in example: _info(Image.open(Images/lena.jpg))
from line #24 of selftest.testimage
Exception raised:
Traceback (most recent call last):
  File ./doctest.py, line 499, in _run_examples_inner
exec compile(source, string, single) in globs
  File string, line 1, in module
  File ./selftest.py, line 22, in _info
im.load()
  File PIL/ImageFile.py, line 180, in load
d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
  File PIL/Image.py, line 375, in _getdecoder
raise IOError(decoder %s not available % decoder_name)
IOError: decoder jpeg not available
1 items had failures:
   1 of  57 in selftest.testimage
***Test Failed*** 1 failures.
*** 1 tests of 57 failed.


Again and again and again.


I found this post  
http://blog.tlensing.org/2008/12/04/kill-pil-–-the-python-imaging-library-headache
which provided the solution.

When you run selftest.py in the Imaging-1.1.6 directory, python finds
the PIL.pth and PIL file and directory, respectively and uses those
instead of the properly compiled versions in the python directories.

So PIL is installed, it IS working perfectly, it's selftest.py that's
failing...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Drawing and Displaying an Image with PIL

2009-01-28 Thread W. eWatson

r wrote:

Change this line:
draw.line((0,0),(20,140), fill=128)

To This:
draw.line((0,0, 20,140), fill=128)

And you should be good to go. Like you said, if you need to combine 2
tuples you can do:
(1,2)+(3,4)
Yes, that's true, but the big question is how to see the final image? 
Either one employees another module or writes the file into a folder, then 
displays it with a paint program?


--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

Web Page: www.speckledwithstars.net/

--
http://mail.python.org/mailman/listinfo/python-list


Re: Drawing and Displaying an Image with PIL

2009-01-28 Thread Peter Otten
W. eWatson wrote:

 r wrote:
 Change this line:
 draw.line((0,0),(20,140), fill=128)
 
 To This:
 draw.line((0,0, 20,140), fill=128)
 
 And you should be good to go. Like you said, if you need to combine 2
 tuples you can do:
 (1,2)+(3,4)
 Yes, that's true, but the big question is how to see the final image?
 Either one employees another module or writes the file into a folder, then
 displays it with a paint program?

For debugging purposes you can just invoke the show() method

im = Image.open(...)
# modify image
im.show() 

If you want to integrate the image into your own Tkinter program -- that is
explained here:

http://effbot.org/tkinterbook/photoimage.htm

Following these instruction you code might become

import Tkinter as tk
import Image
import ImageTk
import ImageDraw
import sys

filename = sys.argv[1]
im = Image.open(filename)

draw = ImageDraw.Draw(im)
draw.line((0, 0) + im.size, fill=128)
draw.line(((0,0),(20,140)), fill=128)


root = tk.Tk()
pi = ImageTk.PhotoImage(im)
label = tk.Label(root, image=pi)
label.pack()
root.mainloop()

Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Drawing and Displaying an Image with PIL

2009-01-28 Thread Bill McClain
On 2009-01-28, W. eWatson notval...@sbcglobal.net wrote:
 Yes, that's true, but the big question is how to see the final image? 
 Either one employees another module or writes the file into a folder, then 
 displays it with a paint program?

Does im.show() not work?

-Bill
-- 
Sattre Press  Tales of War
http://sattre-press.com/   by Lord Dunsany
i...@sattre-press.com http://sattre-press.com/tow.html
--
http://mail.python.org/mailman/listinfo/python-list


Windows PIL installer question

2009-01-28 Thread cjl
Is there any way to run the PIL installer from the command line on
Windows in 'silent' mode, without displaying the install screens or
requiring user interaction?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Windows PIL installer question

2009-01-28 Thread Gabriel Genellina

En Wed, 28 Jan 2009 15:07:54 -0200, cjl cjl...@gmail.com escribió:


Is there any way to run the PIL installer from the command line on
Windows in 'silent' mode, without displaying the install screens or
requiring user interaction?


Is it a .msi?
msiexec /i filename.msi /quiet /log path\to\logfile.log

--
Gabriel Genellina

--
http://mail.python.org/mailman/listinfo/python-list


Re: Drawing and Displaying an Image with PIL

2009-01-28 Thread W. eWatson

Peter Otten wrote:

W. eWatson wrote:


r wrote:

Change this line:
draw.line((0,0),(20,140), fill=128)

To This:
draw.line((0,0, 20,140), fill=128)

And you should be good to go. Like you said, if you need to combine 2
tuples you can do:
(1,2)+(3,4)

Yes, that's true, but the big question is how to see the final image?
Either one employees another module or writes the file into a folder, then
displays it with a paint program?


For debugging purposes you can just invoke the show() method

im = Image.open(...)
# modify image
im.show() 


If you want to integrate the image into your own Tkinter program -- that is
explained here:

http://effbot.org/tkinterbook/photoimage.htm

Following these instruction you code might become

import Tkinter as tk
import Image
import ImageTk
import ImageDraw
import sys

filename = sys.argv[1]
im = Image.open(filename)

draw = ImageDraw.Draw(im)
draw.line((0, 0) + im.size, fill=128)
draw.line(((0,0),(20,140)), fill=128)


root = tk.Tk()
pi = ImageTk.PhotoImage(im)
label = tk.Label(root, image=pi)
label.pack()
root.mainloop()

Peter
My initial quest was to do it in PIL. That seems impossible, and the way out 
is Tkinter. I'm not yet savvy enough with Pythons graphics. I was definitely 
leaning towards PhotoImage as the way out. What module is show in?


Repairing my (0,0), ... to (0,0)+, and. replacing arg with ImageOPen, 
produces a correct solution.


My NM Tech pdf misses the boat on PhotoImage. I've seen your reference 
before, but never looked at PhotoImage. I'll bookmark it. I sure wish it was 
in pdf format.


Thanks.


--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

Web Page: www.speckledwithstars.net/

--
http://mail.python.org/mailman/listinfo/python-list


Drawing and Displaying an Image with PIL

2009-01-27 Thread W. eWatson

Here's my program:

# fun and games
import Image, ImageDraw

im = Image.open(wagon.tif) # it exists in the same Win XP
# folder as the program
draw = ImageDraw.Draw(im)
draw.line((0, 0) + im.size, fill=128)
draw.line((0,0),(20,140), fill=128)

# How show this final image on a display?

root.mainloop()

It has two problems. One is it crashes with:
draw.line((0,0),(20,140), fill=128)
TypeError: line() got multiple values for keyword argument 'fill'

Secondly, it has no way to display the image drawn on. Is it possible, or do 
I have to pass the image off to another module's methods?



--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

Web Page: www.speckledwithstars.net/

--
http://mail.python.org/mailman/listinfo/python-list


Re: Drawing and Displaying an Image with PIL

2009-01-27 Thread r
On Jan 27, 9:15 pm, W. eWatson notval...@sbcglobal.net wrote:
 Here's my program:

 # fun and games
 import Image, ImageDraw

 im = Image.open(wagon.tif) # it exists in the same Win XP
 # folder as the program
 draw = ImageDraw.Draw(im)
 draw.line((0, 0) + im.size, fill=128)
 draw.line((0,0),(20,140), fill=128)

 # How show this final image on a display?

 root.mainloop()

 It has two problems. One is it crashes with:
      draw.line((0,0),(20,140), fill=128)
 TypeError: line() got multiple values for keyword argument 'fill'

 Secondly, it has no way to display the image drawn on. Is it possible, or do
 I have to pass the image off to another module's methods?

 --
                                 W. eWatson

               (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
                Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

                      Web Page: www.speckledwithstars.net/

I have not tried your code but i think you need to put your coodinates
in one tuple. Here is an example from the docs

Example
Example: Draw a Grey Cross Over an Image
import Image, ImageDraw
im = Image.open(lena.pgm)
draw = ImageDraw.Draw(im)
draw.line((0, 0) + im.size, fill=128)
draw.line((0, im.size[1], im.size[0], 0), fill=128)
del draw
# write to stdout
im.save(sys.stdout, PNG)

Hope that helps
--
http://mail.python.org/mailman/listinfo/python-list


Re: Drawing and Displaying an Image with PIL

2009-01-27 Thread W. eWatson

r wrote:

On Jan 27, 9:15 pm, W. eWatson notval...@sbcglobal.net wrote:

Here's my program:

# fun and games
import Image, ImageDraw

im = Image.open(wagon.tif) # it exists in the same Win XP
# folder as the program
draw = ImageDraw.Draw(im)
draw.line((0, 0) + im.size, fill=128)
draw.line((0,0),(20,140), fill=128)

# How show this final image on a display?

root.mainloop()

It has two problems. One is it crashes with:
 draw.line((0,0),(20,140), fill=128)
TypeError: line() got multiple values for keyword argument 'fill'

Secondly, it has no way to display the image drawn on. Is it possible, or do
I have to pass the image off to another module's methods?

--
W. eWatson

  (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
   Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

 Web Page: www.speckledwithstars.net/


I have not tried your code but i think you need to put your coodinates
in one tuple. Here is an example from the docs

Example
Example: Draw a Grey Cross Over an Image
import Image, ImageDraw
im = Image.open(lena.pgm)
draw = ImageDraw.Draw(im)
draw.line((0, 0) + im.size, fill=128)
draw.line((0, im.size[1], im.size[0], 0), fill=128)
del draw
# write to stdout
im.save(sys.stdout, PNG)

Hope that helps
That's pretty much the code I used. In fact, I borrowed it from the pdf. I 
just tried it, and it output %PNG.


I'd like to see this displayed in a window. If the fine had written 
properly, I could see whether it really drew the lines. It did not fail on 
the same draw stmts in my program.


I see my problem, , instead of + between the tuples. I thought I'd seen 
another example where the 2-d tuples could be separated.


I see a ImageFile module, but it's not for writing image files simply.

--
   W. eWatson

 (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
  Obz Site:  39° 15' 7 N, 121° 2' 32 W, 2700 feet

Web Page: www.speckledwithstars.net/

--
http://mail.python.org/mailman/listinfo/python-list


Re: Drawing and Displaying an Image with PIL

2009-01-27 Thread r
Change this line:
draw.line((0,0),(20,140), fill=128)

To This:
draw.line((0,0, 20,140), fill=128)

And you should be good to go. Like you said, if you need to combine 2
tuples you can do:
(1,2)+(3,4)
--
http://mail.python.org/mailman/listinfo/python-list


Re: using PIL for PCA analysis

2009-01-13 Thread Jan Erik Solem



 if i want to do an array of PIL image data i can use
 img=Image.open(myimg.jpg) .convert(L)
 pixelarray=img.getdata()
 
convert(L) is a good way to make images grayscale. An option to using
getdata() is to try numpy's array:
pixelarray = numpy.array(img)
this gives lots of possibilities for working with the images numerically,
like for PCA. (see example code in the link below)



 thus i guess i can build a matrix of a set of  images
 is there something wrong in the way i do this above?may be i can use
 that to find covariance matrix for the set of images?
 
I wrote a short script for doing PCA on images using python, with some
explanations and example code 
http://jesolem.blogspot.com/2009/01/pca-for-images-using-python.html here .
Could be of help to you guys. 

-- 
View this message in context: 
http://www.nabble.com/using-PIL-for-PCA-analysis-tp15606311p21432675.html
Sent from the Python - python-list mailing list archive at Nabble.com.

--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL on 3.x?

2008-12-31 Thread Daniel Fetchinson
 Does anyone know if PIL will be ported to the 3.x branch?

Actually, Guilherme Polo has ported PIL 1.1.6 to python 3.0:

http://mail.python.org/pipermail/image-sig/2008-December/005338.html

Cheers,
Daniel

-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL - font kerning

2008-12-30 Thread carsn
On Dec 23, 9:51 pm, Ivan Illarionov ivan.illario...@gmail.com wrote:
 On Dec 23, 11:22 pm, Ivan Illarionov ivan.illario...@gmail.com
 wrote:



  On 23 дек, 16:44, carsn carsten.kr...@gmail.com wrote:

   Hey all,

   anybody know, if there´s a way to specify the kerning of a font, when
   you draw text withPIL?

   I´d like to achieve the same effect that you get, when you set a
   negative kerning in Gimp/Photshop - ie. reduce the spacing between
   glyphs.

   CanPILdo that or do I use another lib for that?

   Thx for any pointers  some nice xmas days to U all!
   carsten

  No.PILcan't do that. I suggest combination of cairo/pango/pangocairo
  (pycairo and pygtk packages).

  Ivan

 I found a little helper function that does what you want (and more)

 import cairo
 import pango
 import pangocairo

 def draw_text(surface, context, text, font=sans 14, position=None,
 color=None,
 box_width=None,
 alignment=pango.ALIGN_CENTER,
 line_spacing=None, letter_spacing=None,
 extra_kerning=None):
 if color is None:
 color = (0.0, 0.0, 0.0)
 context.set_source_rgb(*color)
 pc = pangocairo.CairoContext(context)
 layout = pc.create_layout()
 layout.set_text(text)
 layout.set_font_description(pango.FontDescription(font))
 if box_width: layout.set_width(box_width)
 layout.set_alignment(alignment)
 if line_spacing: layout.set_spacing(spacing)
 alist = pango.AttrList()
 if letter_spacing:
 alist.insert(pango.AttrLetterSpacing(letter_spacing, 0, len
 (text)))
 if extra_kerning:
 for pos, kern in extra_kerning.iteritems():
 alist.insert(pango.AttrLetterSpacing(kern, pos, pos
 +1))
 layout.set_attributes(alist)
 if position is None:
 width, height = surface.get_width(), surface.get_height()
 w, h = layout.get_pixel_size()
 position = (width/2.0 - w/2.0, height/2.0 - h/2.0)
 context.move_to(*position)
 pc.show_layout(layout)

 And example usage:

 surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
 context = cairo.Context(surface)
 draw_text(surface, context, 'Hello world!',
 font=sans 52, color=(.25,.28,.33),
 letter_spacing=-6000,
 extra_kerning={0:-9000, 1:-1000, 6:6000, 7:-15000, 8:5000,
 9:-7000})

 surface.write_to_png(hello.png)

 --
 Ivan

Works great, thanks a lot!!
--
http://mail.python.org/mailman/listinfo/python-list


PIL - font kerning

2008-12-23 Thread carsn
Hey all,

anybody know, if there´s a way to specify the kerning of a font, when
you draw text with PIL?

I´d like to achieve the same effect that you get, when you set a
negative kerning in Gimp/Photshop - ie. reduce the spacing between
glyphs.

Can PIL do that or do I use another lib for that?

Thx for any pointers  some nice xmas days to U all!
carsten
--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL - font kerning

2008-12-23 Thread Ivan Illarionov
On 23 дек, 16:44, carsn carsten.kr...@gmail.com wrote:
 Hey all,

 anybody know, if there´s a way to specify the kerning of a font, when
 you draw text with PIL?

 I´d like to achieve the same effect that you get, when you set a
 negative kerning in Gimp/Photshop - ie. reduce the spacing between
 glyphs.

 Can PIL do that or do I use another lib for that?

 Thx for any pointers  some nice xmas days to U all!
 carsten

No. PIL can't do that. I suggest combination of cairo/pango/pangocairo
(pycairo and pygtk packages).

Ivan
--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL - font kerning

2008-12-23 Thread Ivan Illarionov
On Dec 23, 11:22 pm, Ivan Illarionov ivan.illario...@gmail.com
wrote:
 On 23 дек, 16:44, carsn carsten.kr...@gmail.com wrote:

  Hey all,

  anybody know, if there´s a way to specify the kerning of a font, when
  you draw text with PIL?

  I´d like to achieve the same effect that you get, when you set a
  negative kerning in Gimp/Photshop - ie. reduce the spacing between
  glyphs.

  Can PIL do that or do I use another lib for that?

  Thx for any pointers  some nice xmas days to U all!
  carsten

 No. PIL can't do that. I suggest combination of cairo/pango/pangocairo
 (pycairo and pygtk packages).

 Ivan

I found a little helper function that does what you want (and more)

import cairo
import pango
import pangocairo

def draw_text(surface, context, text, font=sans 14, position=None,
color=None,
box_width=None,
alignment=pango.ALIGN_CENTER,
line_spacing=None, letter_spacing=None,
extra_kerning=None):
if color is None:
color = (0.0, 0.0, 0.0)
context.set_source_rgb(*color)
pc = pangocairo.CairoContext(context)
layout = pc.create_layout()
layout.set_text(text)
layout.set_font_description(pango.FontDescription(font))
if box_width: layout.set_width(box_width)
layout.set_alignment(alignment)
if line_spacing: layout.set_spacing(spacing)
alist = pango.AttrList()
if letter_spacing:
alist.insert(pango.AttrLetterSpacing(letter_spacing, 0, len
(text)))
if extra_kerning:
for pos, kern in extra_kerning.iteritems():
alist.insert(pango.AttrLetterSpacing(kern, pos, pos
+1))
layout.set_attributes(alist)
if position is None:
width, height = surface.get_width(), surface.get_height()
w, h = layout.get_pixel_size()
position = (width/2.0 - w/2.0, height/2.0 - h/2.0)
context.move_to(*position)
pc.show_layout(layout)

And example usage:

surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
context = cairo.Context(surface)
draw_text(surface, context, 'Hello world!',
font=sans 52, color=(.25,.28,.33),
letter_spacing=-6000,
extra_kerning={0:-9000, 1:-1000, 6:6000, 7:-15000, 8:5000,
9:-7000})

surface.write_to_png(hello.png)

--
Ivan
--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL on 3.x?

2008-12-20 Thread Diez B. Roggisch

Méta-MCI (MVP) schrieb:

Hi!

This info is interesting for many people.
IMO, it's a good idea to write the question in this newsgroup.



Which only makes sense if the author of PIL reads it. Which he seems not 
to (or at least doesn't answer here, as he used to).


Diez
--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL on 3.x?

2008-12-20 Thread M�ta-MCI (MVP)

Hi!

Fredrik Lundh  (Pythonware ; the author of PIL (and ElementTree, and 
many other things)) had, in the past, often give answers.

To me, like to others people.

@-salutations
--
Michel Claveau

--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL on 3.x?

2008-12-20 Thread Daniel Fetchinson
 Does anyone know if PIL will be ported to the 3.x branch?

 Have you considered e-mail to the author?

No, I haven't because in my experience open source software authors
prefer to keep discussion of their software on mailing lists, forums,
etc, where others can benefit from the answers too.

Cheers,
Daniel

-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL on 3.x?

2008-12-20 Thread John Machin
On Dec 21, 12:32 pm, Daniel Fetchinson fetchin...@googlemail.com
wrote:
  Does anyone know if PIL will be ported to the 3.x branch?

  Have you considered e-mail to the author?

 No, I haven't because in my experience open source software authors
 prefer to keep discussion of their software on mailing lists, forums,
 etc, where others can benefit from the answers too.

True, so try a forum where the author has been active within the last
week:

http://mail.python.org/mailman/listinfo/image-sig
--
http://mail.python.org/mailman/listinfo/python-list


PIL on 3.x?

2008-12-19 Thread Daniel Fetchinson
Does anyone know if PIL will be ported to the 3.x branch?

Cheers,
Daniel
-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL on 3.x?

2008-12-19 Thread John Machin
On Dec 20, 6:55 am, Daniel Fetchinson fetchin...@googlemail.com
wrote:
 Does anyone know if PIL will be ported to the 3.x branch?

Have you considered e-mail to the author?



--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL on 3.x?

2008-12-19 Thread M�ta-MCI (MVP)

Hi!

This info is interesting for many people.
IMO, it's a good idea to write the question in this newsgroup.

@-salutations
--
Michel Claveau

--
http://mail.python.org/mailman/listinfo/python-list


Re: something else instead of PIL?

2008-12-18 Thread imageguy
On Dec 17, 3:48 pm, Reimar Bauer r.ba...@fz-juelich.de wrote:
 Hi

 what has happened to PIL? No updates since two years.

 Or does one know an alternative lib for resizing images?

 cheers
 Reimar

I have found the FreeImage library with the Python bindings quite
workable. I work with multi-page TIF images and this seemed to be the
best option.

 The FreeImage library seems to be actively maintained too (Last
release in July 08 with updates to many of the image processing plug-
ins).  The python bindings took me a bit to understand as they try to
emulate PIL, however they are implemented using ctypes, so you can
change/manage yourself if needed.  I found working directly with the
functions exported from the .dll the best option and gave the best
performance.

Freeimage site: http://freeimage.sourceforge.net/
Python bindings: http://freeimagepy.sourceforge.net/

Hope that helps.  Good luck.  Working with images/graphics can make my
brain hurt sometimes.

g.


--
http://mail.python.org/mailman/listinfo/python-list


Re: something else instead of PIL?

2008-12-18 Thread Reimar Bauer
s...@pobox.com schrieb:
 Reimar Hi what has happened to PIL? No updates since two years.
 
 It's well-written, stable code.  As far as I know it does what people want
 (at least it's done everything I've needed when I've used it).  Why should
 it matter that there hasn't been an official release in two years?
 

I am interested to get some new features added e.g. some special
conversion routines for colorblind people.
http://scien.stanford.edu/class/psych221/projects/05/ofidaner/colorblindness_project.htm

How can that be archieved?

cheers
Reimar
--
http://mail.python.org/mailman/listinfo/python-list


Re: something else instead of PIL?

2008-12-18 Thread Reimar Bauer
imageguy schrieb:
 On Dec 17, 3:48 pm, Reimar Bauer r.ba...@fz-juelich.de wrote:
 Hi

 what has happened to PIL? No updates since two years.

 Or does one know an alternative lib for resizing images?

 cheers
 Reimar
 
 I have found the FreeImage library with the Python bindings quite
 workable. I work with multi-page TIF images and this seemed to be the
 best option.
 
  The FreeImage library seems to be actively maintained too (Last
 release in July 08 with updates to many of the image processing plug-
 ins).  The python bindings took me a bit to understand as they try to
 emulate PIL, however they are implemented using ctypes, so you can
 change/manage yourself if needed.  I found working directly with the
 functions exported from the .dll the best option and gave the best
 performance.
 
 Freeimage site: http://freeimage.sourceforge.net/
 Python bindings: http://freeimagepy.sourceforge.net/
 
 Hope that helps.  Good luck.  Working with images/graphics can make my
 brain hurt sometimes.
 
 g.
 
 

thanks!

Reimar
--
http://mail.python.org/mailman/listinfo/python-list


Re: something else instead of PIL?

2008-12-18 Thread skip

Reimar I am interested to get some new features added e.g. some special
Reimar conversion routines for colorblind people.
Reimar 
http://scien.stanford.edu/class/psych221/projects/05/ofidaner/colorblindness_project.htm

Reimar How can that be archieved?

Contact Fredrik Lundh? http://effbot.org/

Skip
--
http://mail.python.org/mailman/listinfo/python-list


something else instead of PIL?

2008-12-17 Thread Reimar Bauer
Hi

what has happened to PIL? No updates since two years.

Or does one know an alternative lib for resizing images?

cheers
Reimar
--
http://mail.python.org/mailman/listinfo/python-list


Re: something else instead of PIL?

2008-12-17 Thread skip

Reimar Hi what has happened to PIL? No updates since two years.

It's well-written, stable code.  As far as I know it does what people want
(at least it's done everything I've needed when I've used it).  Why should
it matter that there hasn't been an official release in two years?

-- 
Skip Montanaro - s...@pobox.com - http://smontanaro.dyndns.org/
--
http://mail.python.org/mailman/listinfo/python-list


Re: something else instead of PIL?

2008-12-17 Thread Chris Rebert
On Wed, Dec 17, 2008 at 12:48 PM, Reimar Bauer r.ba...@fz-juelich.de wrote:
 Hi

 what has happened to PIL? No updates since two years.

The Python Imaging Library is still current; I guess they just haven't
found any new bugs or seen fit to add new functionality in a while,
though I presume they'll start working on a Python 3.0 port
eventually.

If you don't like PIL, there's always the (much less popular) Python
bindings to ImageMagick:
http://www.imagemagick.org/script/api.php#python

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: something else instead of PIL?

2008-12-17 Thread Daniel Fetchinson
 what has happened to PIL? No updates since two years.

 The Python Imaging Library is still current; I guess they just haven't
 found any new bugs or seen fit to add new functionality in a while,
 though I presume they'll start working on a Python 3.0 port
 eventually.

That's actually an interesting question. Does anybody know if PIL is
being ported to 3.0? Are there such plans? Maybe even code?

Cheers,
Daniel

-- 
Psss, psss, put it down! - http://www.cafepress.com/putitdown
--
http://mail.python.org/mailman/listinfo/python-list


PIL (python imaging library) or Mathematics help both appreciated

2008-11-24 Thread amine
well, here is the background.  I have images of objects (cars,
clothes, ...) with a white background in most of the cases

I have to build a function with PIL that takes away the background.
it seems simple, just look for the white and make it transparent but
the problem is in reality much more complex:
1) the image could contain some white inside the object (e.g. shoes
with some white in between straps)
2) there are often pixels that are part of the background but have a
colour different from white which leaves a few points throughout the
image

to be more concrete:
here is a bit of code of what i've made so far

def transparent(im):
#i take all the images of the pixel
pixels = list(im.getdata())
#i convert the image into png
if im.mode != 'RGBA':
 im = im.convert('RGBA')
#i create a new image with the same dimension with one unique layer
for transparency
width , height = im.size
gradient = Image.new('L', (width,height))
white = { 'r' : 255 , 'g' : 255, 'b' : 255 }
#i browse the pixels of the image
for y in range(height):
 yp = y * width
 for x in range(width):
  xy = yp + x
  pix = pixels[xy]
  #the color of the current pixel
  c = { 'r' : pix[0] , 'g' : pix[1], 'b' : pix[2] }
  #i calculate the vectorial distance between the current color and
the color white
  d = sqrt( pow((c['r']- white['r'] ),2) + pow((c['g'] - white['g']),
2) + pow((c['b'] - white['b']),2) )
  if d  5 :
   #if it is more or less white, i make the pixel transparent
   gradient.putpixel((x,y) , 0 )
  else:
   #otherwise i show the color
   gradient.putpixel((x,y) , 255)

after the layer of transparency of the new image is done, the
algorithm works generally fine except there are some small but
noticeable quality issues.  i am just asking myself if there is maybe
not a better approach either in terms of algorithms or even
mathematics or maybe refine the algorithm that i've create.  anything
would help.

i know the function will not be 100% precise but I just hope the image
can be presentable and that the image is homogenous.

thank you in advance for your help.
--
http://mail.python.org/mailman/listinfo/python-list


Re: PIL (python imaging library) or Mathematics help both appreciated

2008-11-24 Thread Arnaud Delobelle
Well not much maths in my answers but...

On 24 Nov, 08:52, amine [EMAIL PROTECTED] wrote:
 well, here is the background.  I have images of objects (cars,
 clothes, ...) with a white background in most of the cases

 I have to build a function with PIL that takes away the background.
 it seems simple, just look for the white and make it transparent but
 the problem is in reality much more complex:
 1) the image could contain some white inside the object (e.g. shoes
 with some white in between straps)

A simple solution would be to start with a transparent pixel in the
top left corner say, then scan the image from left to right (line by
line): if the current pixel is white (or pale enough) and has a
transparent pixel above it or to its left, then make it transparent.

I remember when I was a kid playing graphical adventure games on my
C64, you could actually see this happening as the picture was being
built on the screen (as a floppy could only contain around 160k, you
couldn't store bitmaps unless you had very few pictures).

 2) there are often pixels that are part of the background but have a
 colour different from white which leaves a few points throughout the
 image

What you're doing is fine I think: calculate the distance to white.

HTH

--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list


<    1   2   3   4   5   6   7   8   9   10   >