2

I have created website where users can upload image with any size.

I have served images with get_serving_url function. I have added to end of image modifiers to resize image to 200px size.

http://127.0.0.1:8080/_ah/img/dtrh0i6I_V5JGulg2_LKZw===s200

I have uploaded image 1000x800 - and all right - I have image with size 200x160

If I have uploaded image 100x50 - in result I have resized image with size 200x100. But this is not a good. I need to show original small image, if image size lower that 200px.

How to do this on Google App Engine + Python with get_serving_url?

Anton Danilchenko
  • 2,318
  • 1
  • 25
  • 24

1 Answers1

0

What you need can't be done automatically using get_serving_url.

I think the easiest way to implement that would be saving the image along with a needs_resize property and calling get_serving_url without size parameter if that is not the case (which serves the original image).

Eren Güven
  • 2,314
  • 19
  • 27
  • Yes, if I have not set =s200, than image shown in original size 100x50. But, in template I use url to image, and need to show correct image without additional logic in template. – Anton Danilchenko Sep 01 '11 at 10:41
  • Maybe I need to re-implement `/_ah/img/...` to show image in original size and ignore =sXX property, if image is lover than XX size? – Anton Danilchenko Sep 01 '11 at 10:48
  • 1
    Either you send the image URL to the template or call `get_serving_url` in the template. Write a wrapper around it. As I said, "only resize if bigger" type of logic is not built-in. – Eren Güven Sep 01 '11 at 10:52
  • In this case I need to make query to blob store each time to retrieve information about image height and width? – Anton Danilchenko Sep 01 '11 at 11:45
  • @Anton How are you getting the URL in the first place? Store the image size alongside. – Nick Johnson Sep 05 '11 at 04:58
  • @Nick I have upload image separately, and after this attach blob key to another model instance. On this step I cant get size of image, because size of image (WxH) available only in uploading handler. – Anton Danilchenko Sep 06 '11 at 07:00
  • @Anton Then add size parameters to the model that stores the blob key. – Nick Johnson Sep 06 '11 at 07:06