working on it ...

Filters

Explore Public Snippets

Sort by

Found 1,566 snippets matching: imgur

    public by clsw  350044  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 api.imgur.com, 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();
                try
                {
                    //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("https://api.imgur.com/3/image", 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  2132  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('//i.imgur.com/tNy5Bvz.png');
      background-repeat: repeat;
      background-position: left top;
    }
    

    external by Github  45  0  1  0

    http://imgur.com/gallery/xogPr http://imgur.com/gallery/Qd1jV http://imgur.com/gallery/Z0vc6 http://imgur.com/gallery/jtBIf http://imgur.com/gallery/7TZOC http://imgur.com/gallery/4Kqml http://imgur.com/gallery/T3h6a http://imgur.com/gallery/6XOpl http...

    http://imgur.com/gallery/xogPr http://imgur.com/gallery/Qd1jV http://imgur.com/gallery/Z0vc6 http://imgur.com/gallery/jtBIf http://imgur.com/gallery/7TZOC http://imgur.com/gallery/4Kqml http://imgur.com/gallery/T3h6a http://imgur.com/gallery/6XOpl http://imgur.com/gallery/m85nv http://imgur.com/gallery/aIwRi http://imgur.com/gallery/UhLSj http://im
    http://imgur.com/gallery/xogPr
    http://imgur.com/gallery/Qd1jV
    http://imgur.com/gallery/Z0vc6
    http://imgur.com/gallery/jtBIf
    http://imgur.com/gallery/7TZOC
    http://imgur.com/gallery/4Kqml
    http://imgur.com/gallery/T3h6a
    http://imgur.com/gallery/6XOpl
    http://imgur.com/gallery/m85nv
    http://imgur.com/gallery/aIwRi
    http://imgur.com/gallery/UhLSj
    http://imgur.com/gallery/YIKxG
    http://imgur.com/gallery/BERId
    http://imgur.com/gallery/f4vll
    http://imgur.com/gallery/JNG7g
    
    
    

    external by Github  34  0  1  0

    http://imgur.com/gallery/bwY05XX http://imgur.com/gallery/inK1h http://imgur.com/gallery/hQrlX http://imgur.com/gallery/07o5L http://imgur.com/gallery/u0GKy http://imgur.com/gallery/jF0m9 http://imgur.com/gallery/XS4eF http://imgur.com/gallery/SpXkA

    http://imgur.com/gallery/bwY05XX http://imgur.com/gallery/inK1h http://imgur.com/gallery/hQrlX http://imgur.com/gallery/07o5L http://imgur.com/gallery/u0GKy http://imgur.com/gallery/jF0m9 http://imgur.com/gallery/XS4eF http://imgur.com/gallery/SpXkA: gistfile1.txt
    http://imgur.com/gallery/bwY05XX
    http://imgur.com/gallery/inK1h
    http://imgur.com/gallery/hQrlX
    http://imgur.com/gallery/07o5L
    http://imgur.com/gallery/u0GKy
    http://imgur.com/gallery/jF0m9
    http://imgur.com/gallery/XS4eF
    http://imgur.com/gallery/SpXkA
    
    
    

    external by Github  22  0  1  0

    http://imgur.com/gallery/qdWED http://imgur.com/gallery/a3IOv http://imgur.com/gallery/VvaeF http://imgur.com/gallery/F1EWW http://imgur.com/gallery/ajkPS http://imgur.com/gallery/BQMO3 http://imgur.com/gallery/cjs4k http://imgur.com/gallery/ddigF http...

    http://imgur.com/gallery/qdWED http://imgur.com/gallery/a3IOv http://imgur.com/gallery/VvaeF http://imgur.com/gallery/F1EWW http://imgur.com/gallery/ajkPS http://imgur.com/gallery/BQMO3 http://imgur.com/gallery/cjs4k http://imgur.com/gallery/ddigF http://imgur.com/gallery/9eqli http://imgur.com/gallery/njfTD http://imgur.com/gallery/kidOl http://im
    http://imgur.com/gallery/qdWED
    http://imgur.com/gallery/a3IOv
    http://imgur.com/gallery/VvaeF
    http://imgur.com/gallery/F1EWW
    http://imgur.com/gallery/ajkPS
    http://imgur.com/gallery/BQMO3
    http://imgur.com/gallery/cjs4k
    http://imgur.com/gallery/ddigF
    http://imgur.com/gallery/9eqli
    http://imgur.com/gallery/njfTD
    http://imgur.com/gallery/kidOl
    http://imgur.com/gallery/d0rjx
    http://imgur.com/gallery/HAfg3
    http://imgur.com/gallery/ol8mc
    
    
    

    external by Github  82  0  1  0

    http://imgur.com/gallery/uFWisph http://imgur.com/gallery/IPweRnV http://imgur.com/gallery/5YHk2P7 http://imgur.com/gallery/e6ltdGW http://imgur.com/gallery/xBzVLRB http://imgur.com/gallery/COhEIV4 http://imgur.com/gallery/TUPYLpm http://imgur.com/gall...

    http://imgur.com/gallery/uFWisph http://imgur.com/gallery/IPweRnV http://imgur.com/gallery/5YHk2P7 http://imgur.com/gallery/e6ltdGW http://imgur.com/gallery/xBzVLRB http://imgur.com/gallery/COhEIV4 http://imgur.com/gallery/TUPYLpm http://imgur.com/gallery/RabWZkQ http://imgur.com/gallery/ivQDhab http://imgur.com/gallery/WMlHTz1 http://imgur.com/gal
    http://imgur.com/gallery/uFWisph
    http://imgur.com/gallery/IPweRnV
    http://imgur.com/gallery/5YHk2P7
    http://imgur.com/gallery/e6ltdGW
    http://imgur.com/gallery/xBzVLRB
    http://imgur.com/gallery/COhEIV4
    http://imgur.com/gallery/TUPYLpm
    http://imgur.com/gallery/RabWZkQ
    http://imgur.com/gallery/ivQDhab
    http://imgur.com/gallery/WMlHTz1
    http://imgur.com/gallery/KC0i6iN
    
    

    external by Github  22  0  1  0

    http://imgur.com/gallery/H79p9 http://imgur.com/gallery/PJa3q http://imgur.com/gallery/FrpcY http://imgur.com/gallery/q220Q http://imgur.com/gallery/PW1QW http://imgur.com/gallery/00jdA http://imgur.com/gallery/PVVb4

    http://imgur.com/gallery/H79p9 http://imgur.com/gallery/PJa3q http://imgur.com/gallery/FrpcY http://imgur.com/gallery/q220Q http://imgur.com/gallery/PW1QW http://imgur.com/gallery/00jdA http://imgur.com/gallery/PVVb4: gistfile1.txt
    http://imgur.com/gallery/H79p9
    http://imgur.com/gallery/PJa3q
    http://imgur.com/gallery/FrpcY
    http://imgur.com/gallery/q220Q
    http://imgur.com/gallery/PW1QW
    http://imgur.com/gallery/00jdA
    http://imgur.com/gallery/PVVb4
    
    
    

    external by montanaflynn  830  1  3  0

    Scrape imgur gifs: http://imgur.com/search/score/all?q_type=anigif&q_all=

    Scrape imgur gifs: http://imgur.com/search/score/all?q_type=anigif&q_all=: imgur-gif-scraper.js
    $('.post').each(function (index) {
      var requestBody = {
        source: 'https://imgur.com/' + $(this).attr('id'),
        title: $(this).find('div.hover p').text(),
        attribution: {
          site: 'imgur',
          url: 'https://imgur.com/' + $(this).attr('id')
        }
      }
      var url = 'https://api.gifs.com/media/import'
      $.post(url, JSON.stringify(requestBody)).done(function (res) {
        console.log(res.success.page)
      })
    })
    
    
    

    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: macshots.py
    #!/usr/bin/env python3
    
    import appdirs
    from imgurpython import ImgurClient
    from watchdog.observers import Observer
    from watchdog.events import FileSystemEventHandler
    from pync import Notifier
    
    import os
    import json
    import webbrowser
    import time
    import subprocess
    
    
    class NewScreenshotEventHandler(FileSystemEventHandler):
    
        def on_created(self, event):
            handle_path(event.src_path)
    
        def on_moved(self, event):
            handle_path(event.dest_path)
    
    
    def ding():
        subprocess.call(['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
                         filename.endswith('.png'))
        if not is_screenshot:
            return
    
        try:
            resp = client.upload_from_path(filepath, anon=False)
        except Exception as e:
            print(e)
            return
    
        link = resp['link']
        print(link)
        to_clipboard(link)
        Notifier.notify(link, title='Upload Complete', open=link)
        ding()
    
    
    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)
    
    try:
        with open(creds_path) as f:
            credentials = json.load(f)
    
    except OSError:
        authorization_url = client.get_auth_url('pin')
        webbrowser.open(authorization_url)
    
        print()
        print('Go here to authorize this app:')
        print(authorization_url)
        print()
    
        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)
    observer.start()
    
    print('macshots is ready!')
    
    try:
        while True:
            time.sleep(1)
    
    except KeyboardInterrupt:
        observer.stop()
    
    observer.join()
    
    
    

    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-[...].cloudfunctions.net';
    
    exports.album = function album (req, res) {
    
      if (req.path === undefined || req.path.length <= 1) {
        res.status(400).send('{"error":"No Data"}');
        return;
      }
    
      var params = {
      	url: 'https://api.imgur.com/3/album/'+req.path,
              headers: {
                  "Authorization": 'Client-ID ' + IMGUR_API_KEY
              }
       };
    
       request.get(params, function(err, response, data){
        if(err){
          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 = imgurRes.data.images;
    
        if(imgurRes.data.error || 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='https://www.ctis.me/projects/imgurProxy/style.css' 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>";
    
        res.send(responseHTML);
       });
    };
    
    
    
    
    • Public Snippets
    • Channels Snippets