[OSM-dev] NOT-saving empty Mapnik tiles

marqqs at gmx.eu marqqs at gmx.eu
Sat Aug 13 10:53:50 BST 2011

Hello again...

unfortunately, this line did not work:

> im.save(buf, 'png256')

I tried im.tostring() too, did not work either. This is the error message:

Traceback (most recent call last):
  File "./mapnik_tile.py", line 143, in <module>
    im.save(buf, 'png256')
Boost.Python.ArgumentError: Python argument types in
    Image.save(Image, instance, str)
did not match C++ signature:
    save(mapnik::Image32, std::string)
    save(mapnik::Image32, std::string, std::string)

Do you have an idea what went wrong?

To Yves:
Thanks for the suggestion. Yes, this would save a bit disk space but no inodes. Because of the current block size (4096 bytes) not much of disk space could be saved.

-------- Original-Nachricht --------
> Datum: Fri, 12 Aug 2011 20:02:27 +0200
> Von: Igor Podolskiy <igor.podolskiy at vwi-stuttgart.de>
> An: dev at openstreetmap.org, marqqs at gmx.eu
> Betreff: Re: [OSM-dev] NOT-saving empty Mapnik tiles

> Hi Markus,
> sorry, I misread your first mail, it's not a PIL.Image but a 
> mapnik.Image - it doesn't have all those fancy methods of a PIL Image. I 
> don't know how to convert from mapnik to PIL now, either :( My fault.
> But I just had another idea.
> If your current method works for you and it's just about reducing disk 
> IO, you just could use StringIO [1] or the like and save the PNG image 
> to a buffer first, then check its length and conditionally save it to
> disk:
> import StringIO
> buf = StringIO.StringIO()
> # ... render the image somehow here ...
> im.save(buf, 'png256')
> if buf.len > 116:
>     f = open(tile_name, 'wb')
>     f.write(buf.getvalue())
>     f.close()
> buf.close()
> Bye
> Igor
> [1] http://docs.python.org/library/stringio.html

More information about the dev mailing list