merge two png pic
cocobear
cocobear.cn at gmail.com
Mon Aug 3 21:44:49 EDT 2009
On Jul 31, 2:52 pm, Peter Otten <__pete... at web.de> wrote:
> cocobear wrote:
> > On Jul 29, 9:20 am, cocobear <cocobear... at gmail.com> wrote:
> >> Thistwopngfile has their own palette
>
> >> >>> im1.mode
> >> 'P'
> >> >>> im.mode
> >> 'P'
> >> >>> im.getpalette == im1.getpalette
>
> >> False
>
> >> I can use this code tomergetwopngpictogether:
>
> >> Map = Image.new("RGB", (x,y))
> >> Map.paste(im, box)
> >> Map.paste(im1,box)
>
> >> Map = Map.convert("L", optimize=True, palette=Image.ADAPTIVE)
>
> >> But if thetwopngpicis too big , or if I have tomergemorepic
> >> together, I will get MemoryError:
>
> >> >>> Image.new("RGB",(44544,38656))
>
> As a workaround you could split the image into tiles that fit into your
> machine's RAM. Or you could try to do the rendering on a 64-bit system.
> You'll need at least
>
> >>> 3*44544*38656./(2**30)
>
> 4.8109130859375
>
> 5 gigabytes for the target image plus memory for the biggest source image.
> Alternatively there are probably tools that can keep parts of the image on
> disk (imagemagick, maybe? you'll have to check yourself or ask in a
> specialized forum). As a last resort you should be able to write such a tool
> yourself. I don't know how hard it would be to generate the PNG, but the RGB
> pasting should be trivial.
>
Thanks for you reply.
Map = Image.new("RGB", ((x2-x1+1)*256, (y2-y1+1)*256))
for x in range(x1,x2+1):
for y in range(y1,y2+1):
#print x,y
filename = "v=cn1.11&hl=zh-CN&x=%d&y=%d&z=%d&s=Galile" %
(x,y,z)
#
box = ((x-x1)*256, (y-y1)*256, (x-x1)*256+256, (y-y1)
*256+256)
#print box
im = Image.open(filename+".png")
Map.paste(im, box)
temp = "temp_map.png"
Map.save(temp)
del Map
print "converting"
Map = Image.open(temp)
Map = Map.convert("P", palette=Image.ADAPTIVE)
Now I use code above, the problem is when I create a RGB image, I need
four times spaces then a 'P' mode image.
Can I directly create a 'P' mode image, and paste those images on?
(NOTICE: this small image has different palette)
> >> Traceback (most recent call last):
> >> File "<stdin>", line 1, in <module>
> >> File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 1710, in
> >> new
> >> return Image()._new(core.fill(mode, size, color))
> >> MemoryError
>
> >> How can I directlymergetwopicto a ‘P' modepngwith palette.
>
> > Nobody replied.
>
> What do you want to do with such a big image? You will run into the same
> limitation when you are trying to display it.
>
I want to download a map from google map with high precision
> Peter
More information about the Python-list
mailing list