Question

I have uploaded a static image (e.g., at location: /images/no-image.jpg) as part of my code that gets used as the default image when there is no specific image available (basically of the type: "no image for this item")

Just realized that this image may have to be served at more than one size (I have uploaded -- and want to upload -- just one size).

How do I resize this image using Google's Images Service?

If I use the example shown at https://developers.google.com/appengine/docs/java/images/#Java_Transforming_images_in_Java , that means having to read the file, apply the transform, then write a servlet to serve up the file... which seems like a lot of work. Is there an easier way?

Will it be easier to just upload the image to the BlobStore :-)?

Was it helpful?

Solution

You can add the following lines to your CSS file:

.placeholder {
    background-image:url('../images/bg.png');
    background-repeat:no-repeat;
    background-size:contain;
    background-position:center;
}

Now, when you don't have a specific image to serve, simply add "placeholder" class to your container element.

Remember to make this image cacheable.

OTHER TIPS

I strongly recommend using the getServingUrl function for serving and resizing images for two reasons:

  1. simpler to use. to resize, you just append parameters to the image url

  2. It will significantly reduce the load off your instances, since the images are served without a servlet, but with google magic

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top