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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With