Add images to your portfolio

As they say, a picture’s worth 1000 words

Effective scientific communication is often built on visual evidence, so it’s important to be able to include photographs, figures, and maps into your webpages.

Authors

Nate Quarderer

Elsa Culler

Published

October 16, 2024

Follow along with our video demo here:

DEMO: Add images to your portfolio (Short course) by ESIIL

Images make your website easier to understand

The following code will display an image from the internet using Markdown:

![Mississippi Delta](https://deltax.jpl.nasa.gov/img/delta-google-earth.jpg)

Mississippi Delta

Image source: image of the Mississippi Delta from the Jet Propulsion Laboratory DeltaX project

Important

Always make sure you have permission to use images, and give credit to your image sources. Most images are fair to use for education (teaching, research, and study), as long as you give credit to your source. If you later on decide to use your portfolio to make money (for example, if you use it as marketing materials), then you should reconsider what images you are using.

Learn more about fair use from the CU Library Fair Use page.

Adding your own images

Including images from the web is the easiest way to add images to your site, but you will probably want to include your own images! There are three common ways that you can add images you have taken or created to your website:

  1. Uploading an image to your portfolio repository on GitHub
  2. Uploading an image elsewhere and then linking to it
  3. Generate an image with code and render it into your website

We’ll try out the first two options in this lesson. But first, you need to understand the difference between absolute and relative URLs on the web.

Upload an image to GitHub

STEP 1: Create an empty image directory on GitHub

It’s important to keep your files organized in a project like a website. Before uploading any images, you should make a place to put them. By convention, images in most websites are kept in the img directory, but you can name it whatever you want.

git, the system used by GitHub to keep track of changes to files, doesn’t keep a record of directories without any files in them, and as of now you can’t upload an image to a directory that doesn’t exist yet. This puts us in a bit of a pickle! Fortunately, there’s a common solution – we’ll create an empty text file named .keep in the new directory.

Speak Code – why .keep?

You could name your empty placeholder file anything you want. However, there are two good reasons to use .keep as your filename. First, files that start with a dot (.) are hidden in unix-based operating systems like linux and MacOS, which helps avoid clutter when you are looking at your files. Second, adhering to the convention means that anyone else looking at your repository will know what the .keep file is doing there.

To create a img/.keep file, go to the main page of your website repository on GitHub and click the Code tab. Then, find the + menu button on the upper right and select Add a file from the dropdown:

Click add a file

Type `img/.keep into the name field and then commit your changes:

Name the file img/.keep and commit

Click Commit

Click Commit again to confirm
Warning

When you type img/, GitHub will automatically make a folder, so only .keep will be visible in the text box.

STEP 2: Upload your image to the img directory

First, make sure that the name of your image file on your computer is descriptive and machine-readable (doesn’t contain any spaces or special characters other than _, -, or .). You won’t be able to rename your file once you upload it to GitHub.

You should now be in the img directory in your repository. If note, you can get there from the Code tab in your website repository, by clicking on the img directory in the files. From there, click the Add file menu in the upper right, but this time select Upload files:

Click on Add file, then Upload files

Drag your image file, or browse and select it.

Commit file upload

Finally, write a message and click Commit changes: Confirm your file upload commit by clicking commit

Other places to host images

GitHub has a couple of limitations when it comes to hosting images:

  1. The site will not allow you to upload files larger than 100MB
  2. If you make changes to an image file, GitHub will keep all the previous versions, which can make your repository unwieldy to download. If you are generating image files yourself and changing them frequently, consider hosting them somewhere else.

So, where can you host images that you have taken or generated? There are a few options:

  1. You can use the Free Image Hosting service to upload images without an account or giving up any information about yourself. Note that while you retain ownership of these images you are granting a license to Free Image Hosting to use them however they want.
  2. For a final version, you can use a research hosting service like figshare to upload images and get code to embed them in your website.
  3. If you want to use photos you have already uploaded to social media, you can usually get a direct link by right-clicking on the image and selecting Copy Image Link.
  4. You will likely find that most file storage services such as Google Drive and Dropbox don’t provide you with a direct link to images that you can use in a website. You can look for instructions on generating direct links for these files, but they are often unsupported and could change without warning.
  5. There’s another way of hosting on GitHub that doesn’t have the same drawbacks when it comes to large files. You can include files in a release, which creates a direct link to files, but does not attempt to track changes. To get started, follow the instructions from GitHub documentation. Note that once you have a release you can add additional files to it.
Warning

By uploading images to social media or other hosting services, you are sometimes giving up your rights to the image, or granting. Photo apps like Flickr are usually better bets, since they are built for photographers with copyright protection in mind. But be sure to read the fine print when uploading material that is sensitive to you personal or to your community – you can look for the term ownership rights in the Terms and Conditions of whatever sites you use.