[Image-SIG] PIL and rendering images

Jesse Montrose jesse@spine.com
Tue, 7 Aug 2001 08:21:37 -0700


hi there, i'm a happy new PIL user myself.

if i understand your question correctly, i think your problem is in
the jpeg output.  reading in JpegImagePlugin.py:

def DQT(self, marker):
    #
    # Define quantization table.  Support baseline 8-bit tables
    # only.  Note that there might be more than one table in
    # each marker.

    # FIXME: The quantization tables can be used to estimate the
    # compression quality.

i take that to mean that the quantization is fixed (invariable) for
now (maybe i'll take a crack at it once i'm more familiar with the
library in general). lowering jpeg quality loses detail, and gives you
artifacts around fine detail areas.

for example, i'm using small bitmapped fonts (10 point verdana).
saving the file out as a jpg blurs the text more than i'd like but
saving the file out as a gif does a poor job of palette selection and
dithering (another thing i might take a crack at).

i've gotten the best results saving the file out of PIL as a png, then
running it through pbm to do the gif conversion:

   pngtopnm < test.png | ppmquant 256 | ppmtogif > test.gif

that turns out to be the best compromise between the photo elements
and text elements for my project, your mileage may vary.

on another note, as much as it kills me, i'm still not using pngs in
websites meant for general consumption because there are still some
browsers out there that crash trying to load them (even though it's
very few)

On Tue, Aug 07, 2001 at 02:29:42PM +0200, John Angelmo wrote:
> 
> Hi I'm a happy private PIL user
> For a small homepage for my former highschool I'm using PIL/Python to 
> generate jpeg backgrounds (Just haven't changed JPEG to PNG yet)
> 
> The code is fairly simple:
> #!/usr/local/bin/python
> 
> import os, sys
> import Image, ImageDraw
> 
> 
> #def fromhex(s):
> #  s='#cbb99c'
> #  return int(s,16)
> #  fromhex(s[1:3], bla bla
> #  int(s[1:3],16),int(s[3:5],16),int(s[5:7],16)
> 
> #def crtimg(self,infile,im):
> s='#cbb99c'
> t='#a89779'
> infile= 'background'
> print infile
> im = Image.new("RGB",[10,10],(int(s[1:3],16),int(s[3:5],16),int(s[5:7],16)))
> 
> impix = ImageDraw.Draw(im)
> impix.point((2,2),(int(t[1:3],16),int(t[3:5],16),int(t[5:7],16)))
> impix.point((7,2),(int(t[1:3],16),int(t[3:5],16),int(t[5:7],16)))
> impix.point((2,7),(int(t[1:3],16),int(t[3:5],16),int(t[5:7],16)))
> impix.point((7,7),(int(t[1:3],16),int(t[3:5],16),int(t[5:7],16)))
> del impix
> 
> im.save(infile, "JPEG")
> 
> 
> 
> the background looks OK first but if I soom in (about 1500%) I can see 
> that the four dots have created small distortions in the image is there 
> any way to fix this?
> 
> I also get a strange error when I use PIL:
> 
> WARNING: Python C API version mismatch for module _imaging:
>    This Python has API version 1010, module _imaging has version 1007.
> 
> 
> Kind Regards
> 
> John A
> 
> 

-- 
  pgp  14 4b eb f7 62 13 2e c1                    jesse montrose
print  31 95 e6 82 25 64 7b 43                    www.spine.com