working on it ...


Explore Public Snippets

Sort by

Found 1,562 snippets matching: imgur

    public by clsw  350065  0  6  1

    Image upload to API, return direct link. (IMGUR)

    Imgur, one of the best image hosts in the world, has a fantastic API, this is a VERY simple and usable implementation of it, just pass an image to the function and it will return the direct link to yout image, heavily commented and easy to use.
    public string UploadImage(Image img)
                //get a dev key from, anonymous usage (no user auth) only.
                string devkey = "YOUR_CLIENT_ID (e.g. abcde1f234567g8)";
                //define the WebClient we'll use to communicate with Imgur.
                WebClient w = new WebClient();
                //adds the Header to authorize this application with Imgur, must include a valid CLIENT_ID from 'devkey' above.
                w.Headers.Add("Authorization", "Client-ID " + devkey);
                System.Collections.Specialized.NameValueCollection Keys = new System.Collections.Specialized.NameValueCollection();
                    //Converts the image to a byte array so it can be turned into a string for upload.
                    using (MemoryStream stream = new MemoryStream())
                        img.Save(stream, ImageFormat.Png);
                        Keys.Add("image", Convert.ToBase64String(stream.ToArray()));
                    //uploads the string-formatted-image and waits for the response.
                    byte[] responseArray = w.UploadValues("", Keys);
                    dynamic result = Encoding.ASCII.GetString(responseArray);
                    //formats the (long and technical) result into just the direct image link.
                    Regex reg = new Regex("link\":\"(.*?)\""); Match match = reg.Match(result);
                    string url = match.ToString().Replace("link\":\"", "").Replace("\"", "").Replace("\\/", "/");
                    //returns the online address of the image.
                    return url;
                catch (Exception s) { MessageBox.Show(s.Message); return "err"; }

    public by JonahM  2199  1  6  0

    Background Repeat

    Inspired by Google Forms' Code. Just a simple bit of code here for a repeating background image
    body {
      background-color: rgb(231,238,247);
      background-image: url('//');
      background-repeat: repeat;
      background-position: left top;

    external by Github  45  0  1  0 http... http://im

    external by Github  34  0  1  0 gistfile1.txt

    external by Github  22  0  1  0 http... http://im

    external by Github  82  0  1  0

    external by Github  22  0  1  0 gistfile1.txt

    external by montanaflynn  831  1  3  0

    Scrape imgur gifs:

    Scrape imgur gifs: imgur-gif-scraper.js
    $('.post').each(function (index) {
      var requestBody = {
        source: '' + $(this).attr('id'),
        title: $(this).find('div.hover p').text(),
        attribution: {
          site: 'imgur',
          url: '' + $(this).attr('id')
      var url = ''
      $.post(url, JSON.stringify(requestBody)).done(function (res) {

    external by mplewis  127  0  2  0

    Like CloudApp, but for imgur, and free. License: MIT. Don't forget: pip3 install appdirs imgurpython watchdog pync

    Like CloudApp, but for imgur, and free. License: MIT. Don't forget: pip3 install appdirs imgurpython watchdog pync:
    #!/usr/bin/env python3
    import appdirs
    from imgurpython import ImgurClient
    from watchdog.observers import Observer
    from import FileSystemEventHandler
    from pync import Notifier
    import os
    import json
    import webbrowser
    import time
    import subprocess
    class NewScreenshotEventHandler(FileSystemEventHandler):
        def on_created(self, event):
        def on_moved(self, event):
    def ding():['afplay', 'teleport.mp3'])
    def to_clipboard(text):
        os.system('echo %s | tr -d "\n" | pbcopy' % text)
    def handle_path(filepath):
        filename = os.path.basename(filepath)
        is_screenshot = (filename.startswith('Screen Shot ') and
        if not is_screenshot:
            resp = client.upload_from_path(filepath, anon=False)
        except Exception as e:
        link = resp['link']
        Notifier.notify(link, title='Upload Complete', open=link)
    client_id = '3144101f767d911'
    client_secret = 'f4c34e78086ebdd4a433c89460c30d3681a9c4e5'
    client = ImgurClient(client_id, client_secret)
    app_name = 'macshots'
    app_author = 'mplewis'
    creds_file = 'credentials.json'
    app_dir = appdirs.user_data_dir(app_name, app_author)
    creds_path = os.path.join(app_dir, creds_file)
    desktop_dir = os.path.expanduser('~/Desktop')
    os.makedirs(app_dir, exist_ok=True)
        with open(creds_path) as f:
            credentials = json.load(f)
    except OSError:
        authorization_url = client.get_auth_url('pin')
        print('Go here to authorize this app:')
        pin = input('Paste your Imgur PIN here: ')
        credentials = client.authorize(pin, 'pin')
        with open(creds_path, 'w+') as f:
            json.dump(credentials, f)
    access_token = credentials['access_token']
    refresh_token = credentials['refresh_token']
    client.set_user_auth(access_token, refresh_token)
    event_handler = NewScreenshotEventHandler()
    observer = Observer()
    observer.schedule(event_handler, desktop_dir)
    print('macshots is ready!')
        while True:
    except KeyboardInterrupt:

    external by Charlton Trezevant  12  0  1  0

    Google Cloud Function which, when given an Imgur album ID, this will serve a proxied version via imgurProxy.js.

    Google Cloud Function which, when given an Imgur album ID, this will serve a proxied version via imgurProxy.js.: imgurProxy-album.js
    var request = require('request');
    var IMGUR_API_KEY = ' ';
    var PROXY_URL = 'us-central1-[...]';
    exports.album = function album (req, res) {
      if (req.path === undefined || req.path.length <= 1) {
        res.status(400).send('{"error":"No Data"}');
      var params = {
      	url: ''+req.path,
              headers: {
                  "Authorization": 'Client-ID ' + IMGUR_API_KEY
       request.get(params, function(err, response, data){
          res.status(500).send('{"error":"Couldn\'t connect to Imgur"}');
          throw new Error("Failed to read Imgur API response: " + JSON.parse(err));
        var imgurRes = JSON.parse(response.body);
        var images =;
        if( || typeof images[0].link === 'undefined' || images[0].link.indexOf('http') === -1)
    	     res.status(500).send('{"error":"API error or image not found"}');
        var responseHTML = "<head><title>Imgur Album - "+req.path+"</title><link href='' rel='stylesheet' type='text/css'></head><body><div class='imagesContainer'>";
        for(var i = 0; i < images.length; i++){
        	responseHTML += "<div id='image"+i+"' class='imagesContainer image'><img src='https://" + PROXY_URL + "/fetchImage/"+images[i].id+"'/></div>";
        responseHTML += "</div></body></html>";
    • Public Snippets
    • Channels Snippets