I'm using the Python client library for the Picasa Web Albums API to upload some JPEG images to an album. But the photos appear very compressed once uploaded. In Picasa 3.6 there is an option to upload images in their original quality without any compression, but is there are similar option I can use from within the API?
This is some of the code I use to create the photo and insert it into the album:
upload_photo = gdata.photos.PhotoEntry()
upload_photo.summary = atom.Summary(text=title)
upload_photo.title = atom.Title(text=file_name)
upload_photo.text = atom.Text(text='Test')
upload_photo.author = atom.Author(atom.Name(text='Test Author'))
upload_photo.timestamp = gdata.photos.Timestamp(text='%i' %
int(time.mk开发者_StackOverflow中文版time(photo_date.timetuple()) * 1000))
upload_photo.geo = gdata.geo.Where()
upload_photo.geo.Point = gdata.geo.Point()
upload_photo.geo.Point.pos = gdata.geo.Pos(text='%f %f' % (lat, lon))
imgContent = StringIO.StringIO(urlfetch.fetch('http://url.com/image1.jpg').content)
gpclient.InsertPhoto(album_or_uri=album_url, photo=upload_photo,
filename_or_handle=imgContent, content_type='image/jpeg')
I managed to solve this problem myself, and it turned out to be a weird one :-)
I asked around on the Google Group for the Picasa data API and people there were saying that the API does not do any compression when uploading new images. That led me to look at the other code, namely the urlfetch
.
It turned out that the urlfetch
was getting the compressed JPEG image. But why? Was there a parameter I forgot to set? I looked through the documentation and couldn't find any limitations.
And then it suddenly dawned on me what was happening. I was testing this on my local machine using the Google App Engine SDK, which is connected to the internet using mobile broadband from T-Mobile. And T-Mobile uses a proxy to compress images when you download them. For my Firefox browser I use an extension to modify the HTTP headers to prevent this compression during browsing, but of course the urlfetch
was not doing this.
After changing this it is downloading the original quality JPEG and uploads it to Picasa with no problem.
精彩评论