Explain Codes LogoExplain Codes Logo

How do I display images from Google Drive on a website?

html
responsive-design
embed
google-drive
Alex KataevbyAlex Kataev·Sep 27, 2024
TLDR

To display Google Drive-hosted images on a web page, set the share status to public. Embed the image using an <img> tag, integrating a direct URL like so:

  1. Upload your image to Google Drive
  2. Generate a shareable link.* Ensure you've adjusted sharing options to public.
  3. Extract the image's unique ID from this link and insert it into the URL format:
<img src="https://drive.google.com/uc?export=view&id=YOUR_UNIQUE_IMAGE_ID" alt="Image">
  • Remember, sharing is caring... but not for your bank details!

Detailed steps and alternatives

Google Drive is your friend, but to embed its images, you've to know the proper handshake. Let's dive into the nuances, alternatives, and details that can help you out:

Identifying and using image IDs

Every file in Google Drive has a unique ID. Your task: find it, use it. The ID can be extracted from the sharing link of the file, like a secret code hidden in plain sight.

Displaying multiple images

Got an album to share? Use your folder's ID to display multiple images.

<img src="https://drive.google.com/uc?export=view&id=FOLDER_ID/Image1.jpg" /> <img src="https://drive.google.com/uc?export=view&id=FOLDER_ID/Image2.jpg" />

The bypass trick

Don't want to redirect users to Google Drive? Use the 'Get Link' feature and modify the shared link for direct access.

Alternate hosting platform: Google + Photos

Consider Google + Photos as a plan B for hosting images. You can use a similar process as Google Drive for embedding.

Power user extras: Styling and more

Go beyond just displaying images. Use style attributes, get creative with links, and share entire folders with simplicity!

Responsive image styling

Big screens, small screens - they all love well-styled images. Use style attributes to ensure they look great everywhere.

<img src="YOUR_DIRECT_LINK" alt="Image Description" style="max-width:100%; height:auto;" />

Take 'size does matter' jokes elsewhere; my images are always looking good!

Easy-peasy folder embedding

Use gdriv.es for comfort. Convert your entire Google Drive folder into a short URL.

https://gdriv.es/folder_id

And, voila! All images from your folder become effortlessly embeddable—no manual hassles.

Wrapping up the nitty-gritty

After all the hard work, you want your website visitors to enjoy a seamless experience. Modify the link as outlined above to prevent users from being redirected to Google Drive. For credits, remember to credit the source when using code samples or external tools like gdriv.es.