通过 Picasa API 上传图片时如何防止 JPEG 压缩?

发布于 2024-08-18 07:25:24 字数 1029 浏览 6 评论 0原文

我正在为 Picasa 网络使用 Python 客户端库相册 API 用于将一些 JPEG 图像上传到相册。但照片上传后显得非常压缩。在 Picasa 3.6 中,有一个选项可以以原始质量上传图像而不进行任何压缩,但是我可以在 API 中使用类似的选项吗?

这是我用来创建照片并将其插入相册的一些代码:

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.mktime(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'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.mktime(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')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

真心难拥有 2024-08-25 07:25:24

我自己设法解决了这个问题,结果发现这是一个奇怪的问题:-)

我在 Google Group 上询问了 Picasa 数据 API,那里的人说该 API 在上传新图像时不会进行任何压缩。这让我查看了其他代码,即 urlfetch

事实证明,urlfetch 正在获取压缩的 JPEG 图像。但为什么?是不是有什么参数我忘记设置了?我查看了文档,没有发现任何限制。

然后我突然意识到发生了什么事。我正在使用 Google App Engine SDK 在本地计算机上对此进行测试,该计算机使用 T-Mobile 的移动宽带连接到互联网。当您下载图像时,T​​-Mobile 使用代理来压缩图像。对于我的 Firefox 浏览器,我使用扩展来修改 HTTP 标头,以防止在浏览期间进行这种压缩,但 urlfetch 当然不会这样做。

更改此设置后,它会毫无问题地下载原始质量的 JPEG 并将其上传到 Picasa。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文