【问题标题】:Why does Google Images Service convert my WEBP images into JPG when serving them?为什么 Google 图片服务在提供我的 WEBP 图片时会将其转换为 JPG?
【发布时间】:2013-05-28 07:44:57
【问题描述】:

我有许多带有 alpha 的 PNG 图像,我已使用 XnConvert 将它们转换为 WEBP。转换本身进行得很顺利,并且保持 alpha 通道,直到上传到BlobStore

在上传到 blobstore 之前,它看起来像这样:

然后它看起来像这样:

服务网址将其作为 JPG 提供,因此 alpha 通道已被删除。在 App Engine 控制台的 BlobStore 查看器中,它已将内容类型设置为 application/octet-stream,即使上传的文件具有 .webp 文件扩展名。

根据Images API documentation,它应该支持WEBP。

上传图片时我并没有做任何花哨的事情:

List<BlobKey> blobs = blobstoreService.getUploads(req).get("file");
BlobKey blobKey = blobs.get(0);

ImagesService imagesService = ImagesServiceFactory.getImagesService();
ServingUrlOptions servingOptions = ServingUrlOptions.Builder.withBlobKey(blobKey);
String servingUrl = imagesService.getServingUrl(servingOptions);

EDIT:

这是一个服务网址示例: example serving url

我尝试使用 Chrome 以及通过 android 客户端访问它。 这是用于在 android 客户端中访问它的代码,尽管我认为它不相关:

    URL url = new URL(Assets.getServingUrl(resourceName));

    URLConnection connection = url.openConnection();
    connection.connect();

    String contentType = connection.getContentType();
    String fileExt;

    if(contentType.contains("webp"))
        fileExt = ".webp";
    else if(contentType.contains("png"))
        fileExt = ".png";
    else if(contentType.contains("jpeg") || contentType.contains("jpg"))
        fileExt = ".jpg";

    // download the file
    InputStream input = new BufferedInputStream(url.openStream(),8192);
    OutputStream output = MyApp.getAppContext().openFileOutput(resourceName + fileExt,Activity.MODE_PRIVATE);

    byte data[] = new byte[1024];
    int count;
    while ((count = input.read(data)) != -1) {
        output.write(data, 0, count);
    }

    output.flush();
    output.close();
    input.close();


由于可以动态调整图像大小的方式,因此希望通过 Google 图片 API 提供图片。

谁能帮我指出正确的方向来解决这个问题?

EDIT2:

我尝试像这样直接通过 blobstore 提供 blob:blobstoreService.serve(new BlobKey(assetEntity.blobKey), res); 而不是通过图像服务,然后它就可以正常工作了。但是,这不是一种选择,因为以这种方式为它们提供服务所需的实例时间会增加。但至少这将问题缩小到图像服务。

【问题讨论】:

  • 你用什么浏览器来测试这个?
  • @peter 我已经编辑了我的问题以添加更多信息。希望它可以帮助有人帮助我:)

标签: android google-app-engine blobstore webp


【解决方案1】:

您可以将选项=-rw 附加到您的网址。所以你会有类似的东西

http://lh3.ggpht.com/MvNZDvZcBaq_B2MuAj0-Y74sc24WAsOVIQiJzsowu1rVG-ACzGO80xxD9y5OI5dWSCa_Nt41aMmWSSYAbpFE8dW7BhxozH2ikcVLjw=s600-rw

您获得的是 jpeg 缩略图,这是使用 webp 时的默认设置,因为该格式尚未被所有浏览器完全支持。

【讨论】:

  • 谢谢!这是否记录在我错过的某个地方?
  • 您的 -rw 有效,但我发现了一个奇怪的行为。它仅在 s 参数高于 256 时才有效。256 和更低它再次提供 jpg。在此之上,它工作正常。有什么解决办法吗?
  • 该参数尚未记录,我已经为您描述的案例提交了一个错误。
猜你喜欢
  • 2018-12-01
  • 2018-05-10
  • 1970-01-01
  • 2023-01-03
  • 1970-01-01
  • 1970-01-01
  • 2019-01-06
  • 1970-01-01
  • 2016-01-22
相关资源
最近更新 更多