167

Here is the image file: https://gist.github.com/mbostock/5503544#file-thumbnail-png

I tried to drag-and-drop the image file in the edit mode of a gist. That didn't seem to work in Chrome and FireFox.

Update: After back and forth emails with GitHub, this feature (drag-and-drop binary files, including images) isn't supported.

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
Dimitry
  • 4,503
  • 6
  • 26
  • 40
  • 1
    it is easy ... just use any git client ... sync project from , copy file to project's directory, add to repo (git add), commit and sync again ... – Selvin Dec 09 '15 at 17:22
  • 8
    fx ... `git clone https://gist.github.com/6afe8ae9d00c98694dc8`, `cd 6afe8ae9d00c98694dc8`, `xcopy path/to/src/file.any file.any`, `git add any.any`, `git commit -m 'n/a'`, `git push` – Selvin Dec 09 '15 at 17:33
  • Several methods are shown here - https://gist.github.com/cben/46d9536baacb7c5d196c. – slm Jan 28 '19 at 13:32
  • This is now (2021, 8 years later) officially supported. See [my answer below](https://stackoverflow.com/a/69317726/6309). – VonC Sep 24 '21 at 15:38

10 Answers10

141

With a little creativity you can achieve this faster than cloning. To drag/drop:

  1. Create the Gist
  2. Drag an image into the comment field below. This will auto-upload your image file to https://user-images.githubusercontent.com and insert markdown code in the comment field to display the image.
  3. Copy this markdown code to your gist

Note: It is not required that you submit the comment.

Live example

Screenshot of comment field

ow3n
  • 5,974
  • 4
  • 53
  • 51
  • 7
    This is so much better and easier than the SSH approach, thanks. – FoxDeploy Jan 12 '19 at 04:22
  • 5
    Very nice. The file extension of the gist makes a difference. I tried `foobar.png` and saw only text. Obviously, it must be `*.md` to attempt rendering of the markdown. – Synesso Jan 18 '19 at 00:38
  • Hmm, not working for me. Tried it in Chrome and Firefox, and it opens a file dialog, but nothing happens after selecting a file – Cocowalla May 01 '19 at 19:04
  • 1
    @Cocowalla I can confirm. Just submitted a ticket to Github. – ow3n May 02 '19 at 14:55
  • 1
    @Cocowalla Github fixed the issue. This works again. – ow3n May 09 '19 at 15:36
  • 1
    This is the simplest and safest ways to add image. When using ssh, the image will be a large individual image and we can't manage the image like adding a text, or even removing it from the gist, unless you want to delete it from your local (git rm etc) – mochadwi Aug 13 '19 at 13:10
  • 2
    @ow3n Can I ask how will you delete the image if upload the wrong one by mistake?. I'm not asking to remove from the gist itself, but from "user-images.githubusercontent.com". Althoug this is an easier way, I would opt to have a little repo on which I can just manage things even without SSH, using the website capabilities. Usually, I do post on the github blog, and I do use gists as "code" portions for the post. So I just upload images on the current blog repo and pick the "raw" link. – m3nda Dec 22 '19 at 02:43
  • @m3nda These have a relatively hard to guess path so perhaps not an issue? Contact Github if you uploaded an image that could be a security issue https://stackoverflow.com/q/52282847/441878 – ow3n Dec 22 '19 at 12:28
  • I don't guess paths, I do copy the link once uploaded. Unless there's no way to manually delete such bad uploadsI will not use such feature. Contacting support for a single image deletion seems a bad way to do things. Github should provide a way to remove them. – m3nda Dec 22 '19 at 18:20
  • The question is, how long will github keep the images around if they are uploaded like this and not added to the gist? – Qwerty Jun 20 '21 at 15:43
84

I was looking for answer for the same question, here is what I just found:

  1. You can clone your gist as a git repository and add your picture, then push to origin. See loading-thumbnail-into-gist-for.

  2. There is a script written to do this: hecticjeff/gist-img.

I have not tried the above solutions yet, but pretty sure they should work. I did try using defunkt/gist to update my gist with a png but ended up displaying a binary file in my gist.

gsamaras
  • 71,951
  • 46
  • 188
  • 305
Binarycrayon
  • 1,035
  • 6
  • 8
  • 2
    I tested this method and it works with animated GIFs too! See live example: https://gist.github.com/stephenlb/e7ef1e97e3523d9ee9e2#file-python-echo-server-gif it showing publish subscribe python echo server. – Stephen Blum Dec 09 '14 at 06:09
  • Just to make sure: pushing to Github, even if it is to a gist, requires you to be registered and logged into Github, right? – sdaau Jan 26 '15 at 21:12
  • 1
    does the gist-img script actually work? when I post the result of a base64 encoded 12kb image/png file to the github api to create a gist I end up with a text file called test.png as seen [here](https://gist.github.com/tr3buchet/0abc9e23a9bfe05dfb59). I am sure it works great using git, but I want to use this to create gists from boxes where I can't setup git. There's also an [issue](https://github.com/tr3buchet/gister/issues/16) filed against my gist making script to implement this feature. – penchant Feb 20 '16 at 00:08
54
  1. Create a gist or reuse one of your gists.
  2. Clone your gist:

    git clone https://gist.github.com/<hash>.git
    
  3. Add your image to your gist's repository:

    git add my-image.jpg
    
  4. Commit the image:

    git commit -m "adding my image to my gist"
    
  5. Update gist by pushing you modifications:

    git push origin master
    
thiagoh
  • 7,098
  • 8
  • 51
  • 77
9

Clone gist with SSH:

$ git clone git@gist.github.com:<hash>.git mygist

HTTP clone worked fine, but ran into HTTP authentication problems at git push.

rmharrison
  • 4,730
  • 2
  • 20
  • 35
  • 2
    me too, same issue with authing. I think its because have 2FA on. ssh way works (which anyway you should be using) –  Mar 19 '20 at 17:04
4

I was looking for an answer to this same question too, in my case in order to be able to upload PDF files. I had trouble with gist-img (mentioned in another answer to this question). I searched some more and discovered gistup, which worked perfectly, the first time I tried it. It uses node and npm, so it should work on most major operating systems.

mhucka
  • 2,143
  • 26
  • 41
4

How to put images in your Gist url:

  1. upload your image to a place like imgur.com for free, then get the hot-link.
  2. Add a file and give it a markdown extension .md and use markdown image syntax:

![alt text here](https://URL)

  1. ?????
  2. Profit
Gant Laborde
  • 6,484
  • 1
  • 21
  • 30
0

uploading the image somewhere and using the HTML <img> tag works for me

Gubatron
  • 6,222
  • 5
  • 35
  • 37
0

(2013) Update: After back and forth emails with GitHub, this feature (drag-and-drop binary files, including images) isn't supported.

Update Sept. 2021

File attachment support in Markdown for gists

You can now add images and videos to Markdown files in gists by pasting them into the Markdown body or selecting them from the dialog at the bottom of the Markdown file.

For information on supported file types, see the documentation.

As announced by tweet

If you checkout https://gist.github.com, you can now easily include images and videos in your markdown files.

Paste the image in or browse your file system to attach. Let us know what you think.

who-says-you-shouldn-t-ship-on-a-friday-if-you-checkout-scloudtomp3downloader.com

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

This above answer is correct but added a bit more detail...

  1. Create the Gist AND SAVE IT
  2. Since it is saved a comment field will show at the bottom.
  3. Drag an image into the comment field below. This will auto-upload your image file to https://user-images.githubusercontent.com and insert markdown code in the comment field to display the image.
  4. You can check that this code works by toggling to the preview tab at the top of the comment.
  5. Copy this code and EDIT your gist and paste the code
  • Which above answer? The order of answers depends on the sorting a user chooses, so please mention the person that posted the answer or quote it (partially) – ArieKanarie Feb 02 '22 at 08:37
-4

If you upload an image, try these steps:

  • Convert your image into DataURI. For example here on duri.me
  • Then this string insert to GIST as a text file

If you want to convert back, there are several options. For example, this: Converting data URI to image data

Community
  • 1
  • 1
Feri
  • 2,709
  • 1
  • 12
  • 7