Making GIF image twice the size - in memory

M

Miki

Hello All,

I get an image from a web page (via urlopen), and like to make it
twice the size.
I'm trying (using PIL):
---- code ----
from ImageFile import Parser
def double(image_data):
image_parser = Parser()
image_parser.feed(image_data)
im = image_parser.close()
new_size = tuple(map(lambda x: 2 * x, im.size))
new = im.resize(new_size)

return new.tostring("gif", "P") # This is probably the problem,
have no idea

image_data = urlopen(url).read()
image_data = double(image_data)
---- code ----

However I don't get a valid GIF image.

Any ideas?

Thanks,
Miki <[email protected]>
http://pythonwise.blogspot.com
 
M

Michele Petrazzo

Miki said:
Hello All,

Heelo,

I get an image from a web page (via urlopen), and like to make it
twice the size.

However I don't get a valid GIF image.

Your code work well here!
Why you said that the string are invalid?

--code: test_image_double.py

from urllib import urlopen
import Image
from ImageFile import Parser

def double(image_data):
image_parser = Parser()
image_parser.feed(image_data)
im = image_parser.close()
new_size = tuple(map(lambda x: 2 * x, im.size))
new = im.resize(new_size)

return new.tostring("gif", "P"), new, new_size

url = "http://www.google.com/intl/en_ALL/images/logo.gif"
image_data = urlopen(url).read()
image_data, img, new_size = double(image_data)
img_new = Image.fromstring("P", new_size, image_data, "gif")
img_new.save("./out1.gif")
img.save("./out2.gif")
print "PIL version:", Image.VERSION

-- test

michele:~/tmp$ python test_image_double.py && file out1.gif && file out2.gif
(552, 220) 49554
PIL version: 1.1.5
out1.gif: GIF image data, version 87a, 552 x 220
out2.gif: GIF image data, version 87a, 552 x 220
michele:~/tmp$
Any ideas?

Forgot to specify that the data aren't in raw format, but to decode it
with the "gif" encoder?

Ciao,
Michele
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,797
Messages
2,569,648
Members
45,380
Latest member
LatonyaEde

Latest Threads

Top