Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the original image back with ImageServices getServingUrl

getServingUrl is a convenient way to get images from the AppEngine datastore, but it seems to want to auto-transform the image.

For example, if I do this:

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

I get a URL to an image with resized dimensions. For example, if I upload a 960 x 640 image, the default URL will point me to a 512 x 341 image.

So, you say, apply a transform in the URL and set s960. This does return a 960 x 640 image, but it has been transformed -- you can see artifacts in the image if you compare it to the original.

The server is storing the image appropriately, thanks to a technique I found here of doing a crop to the 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 haven't actually looked to see if this contains the original bytes or not, but it doesn't really matter because if I'm going to just be sending bytes back, I might as well just pull the data straight out of the store and set it as the payload of a custom image serving servlet.

Writing this I'm realizing it sounds more like a feature request than a question, so I'll pose it this way: is there a better solution to serving original images than via a custom servlet?

like image 517
Ben Flynn Avatar asked Feb 18 '23 05:02

Ben Flynn


1 Answers

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

By default if you don't add any parameters the image will have maximum size of 512px (same as if you would add =s512). You can read more about getServingUrl in the docs and the options that you have.

like image 200
Lipis Avatar answered Jun 03 '23 19:06

Lipis