Instantly share code, notes, and snippets.

Embed
What would you like to do?
Google’s authentication-less on-the-fly image resizing service

Google's authentication-less on-the-fly image resizing service

I found it while poking around the Google+ HTML. Jotting down some notes felt like a good idea, so here goes. If you know more about this API, let me know, please!

(Word of warning: I spent ~30 minutes on both my experimentation and this here write-up, so it might not be the most thought-provoking, brilliant thing you read today.)

Base URL

https://images1-focus-opensocial.googleusercontent.com/gadgets/proxy

Parameters:

  • url: original image URL
  • container: must be "focus" (i dunno lol)
  • refresh: time (in seconds) to cache it on G's servers
  • resize_w: width in pixels
  • resize_h: height in pixels

You can either specify both resize_* parameters or just one.

Examples

Let's resize that big panorama picture I took in Istanbul last year.

Make it square, 300x300px:

https://images1-focus-opensocial.googleusercontent.com/gadgets/proxy?url=https%3A%2F%2Fdl.dropboxusercontent.com%2Fu%2F7298%2Fblog%2FBlick_von_der_S%25C3%25BCleymaniye-Moschee.jpg&container=focus&resize_w=300&resize_h=300

Make it 750px wide and keep the aspect ration:

https://images1-focus-opensocial.googleusercontent.com/gadgets/proxy?url=https%3A%2F%2Fdl.dropboxusercontent.com%2Fu%2F7298%2Fblog%2FBlick_von_der_S%25C3%25BCleymaniye-Moschee.jpg&container=focus&resize_w=750

Quirks

At least in Chrome, opening the URL in the browser will force a download of a text file (which is actually a JPG). Putting the URL in an <img> tag is fine. Or just use curl.

@edent

This comment has been minimized.

edent commented Jan 2, 2015

Really useful! Do you know if there's a way to specify a maximum width? Like, only resize if over X pixels?

@pajtai

This comment has been minimized.

pajtai commented Jul 1, 2015

Are there any docs for this service? Tried googling a few things, but didn't find anything.

@martijndebruijn

This comment has been minimized.

martijndebruijn commented Dec 29, 2015

@lawloretienne: I have the same problem and I think it is related to the size of the image you want to resize. Try a smaller source image. I don't know what the maximum of the source message is but it looks like something of max 3000px X 3000px.

@sw-ms-roshanparmar

This comment has been minimized.

sw-ms-roshanparmar commented Jan 10, 2018

Hi, it is not working for some of the images. below is the link of image which i used.
image

and i tried to resize it with the following url:
https://images1-focus-opensocial.googleusercontent.com/gadgets/proxy?container=focus&resize_h=15&url=http://115.115.91.41:1904/images/Image988.jpg

but, it still gives the image in same resolution. it is not resizing it.
any help ?

@Sauerstoffdioxid

This comment has been minimized.

Sauerstoffdioxid commented Feb 12, 2018

I've found two more options:

  • no_expand=1: when scaled to a larger size than the image itself is, it will not be resized (e.g. the dimensions set with resize_* act as a maximum but are not forced on smaller images).
    no_expand=0 seems to function as something like "force resize"
  • rewriteMime=image/*: normally the mime type is something like image/png; charset=UTF-8. With this option you can overwrite it. The * functions as a placeholder for whatever mime the image originally had, i. e. rewriteMime=image/* would give image/png if used on a PNG. Note that it won't affect the proxying – you'll still receive the same with or without this option (only the mime type changes)

Some other things:

  • There's a parameter gadget=a, not sure what it's for.
  • Only container and url are required parameters. The value of container=focus is irrelevant as long as it's there.
@ShaMan123

This comment has been minimized.

ShaMan123 commented Apr 11, 2018

does this work?
couldn't get anything to work

@Sauerstoffdioxid

This comment has been minimized.

Sauerstoffdioxid commented Apr 15, 2018

@ShaMan123 Yes, it should. Here's an example:
Github Icon

EDIT: For some reason, GitHub is pulling the original image. Weird. However, the link below should yield a resized version.

URL: http://images1-focus-opensocial.googleusercontent.com/gadgets/proxy?container=focus&gadget=a&no_expand=0&resize_w=64&rewriteMime=image/*&url=https://maxcdn.icons8.com/Share/icon/p1em/Logos/github1600.png

@giautm

This comment has been minimized.

giautm commented Jul 17, 2018

You should use querystring.stringify to encode all params like bellow, or encodeURIComponent to keep original params to url.
Without encoding, all params in this URL will forward to Google rather original service. https://images.unsplash.com/photo-1437422061949-f6efbde0a471?q=80&fm=jpg&s=e23055c9ba7686b8fe583fb8318a1f88

        const params = querystring.stringify({
          container,
          no_expand: Number(noExpand),
          refresh,
          resize_h: height,
          resize_w: width,
          url,
        })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment