Retrieving a source image using ImageServices getServingUrl

getServingUrl is a convenient way to get images from the AppEngine data store, but it looks like it wants to automatically convert the image.

For example, if I do this:

ServingUrlOptions servingUrlOptions = ServingUrlOptions.Builder.withBlobKey(blobKey); String payload = "{ \"image\" : \"" + mImagesService.getServingUrl(servingUrlOptions) + "\" }"; 

I get the url of the resized image. For example, if I upload a 960 x 640 image, by default the URL will point me to a 512 x 341 image.

So you say apply the conversion in the url and install s960. This returns a 960 x 640 image, but it has been converted - you can see artifacts in the image if you compare it with the original.

The server saves the image accordingly, thanks to the method I found here to crop to its original size:

 Image image = ImagesServiceFactory.makeImageFromBlob(blobKey); Transform noOpCrop = ImagesServiceFactory.makeCrop(0, 0, 1, 1); image = mImagesService.applyTransform(noOpCrop, image); LOGGER.info("Stored image " + image.getWidth() + ", " + image.getHeight()); 

I didn’t actually see if it contains the original bytes or not, but it doesn’t really matter, because if I was going to just send the bytes back, I could just pull the data directly from the storage and set it as a payload for the servlet serving a custom image.

Having written this, I understand that this is more like a function request than a question, so I will formulate it as follows: is there a better solution for servicing original images than through my own servlet?

+4
source share
1 answer

You can add =s0 to the end of the generated URL to get the original image.

By default, if you do not add any parameters, the image will have a maximum size of 512 pixels (the same as if you added =s512 ). You can learn more about getServingUrl in the documents and options you have.

+8
source

All Articles