Domanda

I have a number of PNG images with alpha that I have converted to WEBP using XnConvert. The conversion itself goes fine and alpha channel is maintained, until uploaded to the BlobStore

Before upload to the blobstore, it looks like this:
before

and after it looks like this:

after

It's being served as a JPG by the serving url, thus the alpha channel is removed. In the BlobStore viewer in App Engine console, it has set the content-type to application/octet-stream, even though the file uploaded had the .webp file extension.

According to the Images API documentation it's supposed to support WEBP.

I am not doing anything fancy at all when uploading the images:

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:

This is an example serving url: example serving url

I've tried to access it using Chrome and also via an android client. Here is the code used to access it in android client, although I don't think it's relevant:

    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();


Would love to serve the images via the Google Images API because of the way images can be resized on the fly.

Can anyone please help point me in the right direction to solve this?

EDIT2:

I tried serving the blob directly through the blobstore like this: blobstoreService.serve(new BlobKey(assetEntity.blobKey), res); instead of through the Images Service, and then it works fine. However it's not an option because of the increased amount of instance hours that would take up to serve them in this fashion. But at least this narrows the problem down to the Images Service.

È stato utile?

Soluzione

You can append the option =-rw to your url. So you will have something like

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

You were getting a jpeg thumbnail, as that is the default when using webp, since the format is not yet fully supported by all browsers.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top