├── .gitignore ├── guide.gif ├── Unsplash.sublime-settings ├── Default (OSX).sublime-keymap ├── Default (Windows).sublime-keymap ├── Unplash.sublime-commands ├── readme.md └── Unplash.py /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.sh -------------------------------------------------------------------------------- /guide.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urre/Unsplash/HEAD/guide.gif -------------------------------------------------------------------------------- /Unsplash.sublime-settings: -------------------------------------------------------------------------------- 1 | { 2 | // Tumblr image sizes: 1280, 500, 400, 250, 100, 75 3 | // looks for the next bigger image 4 | // e.g. "imgWidth": 1000 5 | // => image width would be 1280px 6 | // e.g. "imgWidth": 450 7 | // => image width would be 500px 8 | "imgWidth": 1280 9 | } -------------------------------------------------------------------------------- /Default (OSX).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "keys": ["alt+s"], 4 | "command": "insert_unsplash_tag" 5 | }, 6 | { 7 | "keys": ["alt+shift+s"], 8 | "command": "insert_unsplash_url" 9 | }, 10 | { 11 | "keys": ["alt+shift+super+s"], 12 | "command": "insert_unsplash_background" 13 | }, 14 | { 15 | "keys": ["alt+shift+super+m"], 16 | "command": "insert_unsplash_markdown" 17 | } 18 | ] -------------------------------------------------------------------------------- /Default (Windows).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "keys": ["shift+alt+s"], 4 | "command": "insert_unsplash_tag" 5 | }, 6 | { 7 | "keys": ["alt+shift+ctrl+s"], 8 | "command": "insert_unsplash_url" 9 | }, 10 | { 11 | "keys": ["alt+shift+ctrl+a"], 12 | "command": "insert_unsplash_background" 13 | }, 14 | { 15 | "keys": ["alt+shift+ctrl+m"], 16 | "command": "insert_unsplash_markdown" 17 | } 18 | ] -------------------------------------------------------------------------------- /Unplash.sublime-commands: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "Unsplash: Insert Image tag", 4 | "command": "insert_unsplash_tag" 5 | }, 6 | { 7 | "caption": "Unsplash: Insert Image URL", 8 | "command": "insert_unsplash_url" 9 | }, 10 | { 11 | "caption": "Unsplash: Insert Background Image CSS", 12 | "command": "insert_unsplash_background" 13 | }, 14 | { 15 | "caption": "Unsplash: Insert Markdown Image Tag", 16 | "command": "insert_unsplash_markdown" 17 | } 18 | ] -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | Unsplash for Sublime Text 2 | ============================= 3 | 4 | Use real dummy images instead of placeholders. Unsplash for Sublime Text brings beautiful images from [Unsplash](http://unsplash.com) 5 | to Sublime Text, your favorite code editor. 6 | 7 | ![Unsplash for Sublime Text](http://unsplashsublime.surge.sh/images/header.jpg) 8 | 9 | ## Features 10 | * Get random image (or image url) from [Unsplash](http://unsplash.com) 11 | * Insert an `img` tag 12 | * Insert image URL 13 | * Insert Background Image CSS 14 | * Insert Markdown Tag 15 | 16 | ## How to use 17 | 18 | * Launch the Command Palette `Shift`+`Cmd`+ P and search for Unsplash 19 | 20 | ### Keyboard shortcuts: 21 | 22 | * `Alt` + `s` → Insert image tag 23 | * `Alt` + `Shift` + `s` → Insert image URL 24 | * `Cmd` + `Alt` + `Shift` + `s` → Insert Background Image CSS 25 | * `Cmd` + `Alt` + `Shift` + `m` → Markdown Image Tag 26 | 27 | ### Settings 28 | 29 | You can specify different images sizes in your `Preferences.sublime-settings`. Tumblr sizes: 1280, 500, 400, 250, 100, 75 pixels. For example: 30 | 31 | { 32 | "imgWidth": 1280 33 | } 34 | 35 | ## Installation 36 | 37 | ### Package Control 38 | 39 | If you have [Package Control](http://wbond.net/sublime_packages/package_control) installed 40 | 41 | * Just search for "Unsplash" to install 42 | 43 | ### Using Git 44 | Go to your Sublime Text Packages directory and clone the repository using: 45 | 46 | git clone https://github.com/urre/Unsplash 47 | 48 | ### Download Manually 49 | 50 | * Download the files using the GitHub .zip download option 51 | * Unzip the files and rename the folder to `Unsplash` 52 | * Copy the folder to your Sublime Text `Packages` directory 53 | 54 | ## FAQ 55 | 56 | #### Which version of Sublime Text does this support? 57 | Both Sublime Text 2 and 3. 58 | 59 | ## Changelog 60 | 61 | + **1.1.2** Added Windows Keyboard Shortcuts 62 | + **1.1.1** Added keyboard shortcut for Markdown Image Tag 63 | + **1.1.0** Added support for Markdown Image Tag 64 | + **1.0.0** Fetch images directly via the Tumblr API. Bug fix: use `background` instead of `background image`. Added settings file for fetching [different sizes](https://github.com/urre/Unsplash#settings) 65 | 66 | ## Notes 67 | 68 | Images from Unsplash is free [do whatever you want](http://creativecommons.org/publicdomain/zero/1.0) (CC0 1.0 Universal (CC0 1.0)) 69 | 70 | You will find photo credits under each photo on [Unsplash](http://unsplash.com) -------------------------------------------------------------------------------- /Unplash.py: -------------------------------------------------------------------------------- 1 | import sublime, sublime_plugin, random, os, json 2 | import xml.etree.ElementTree as ET 3 | 4 | class InsertUnsplashCommand(sublime_plugin.TextCommand): 5 | def run(self, edit, args): 6 | 7 | sublimeVersion = int(sublime.version()) 8 | st2 = False 9 | st3 = False 10 | 11 | if sublimeVersion < 3000: 12 | st2 = True 13 | from urllib import urlopen 14 | else: 15 | st3 = True 16 | import urllib.request 17 | 18 | tumblr_name = 'unsplash' 19 | api_endpoint = 'http://unsplash.tumblr.com/api/read?num=100?type=photo' 20 | photoUrls = [] 21 | settings = sublime.load_settings('Unsplash.sublime-settings') 22 | imgWidth = settings.get('imgWidth', 10) 23 | 24 | if st2: 25 | resp = urlopen(api_endpoint) 26 | else: 27 | resp = urllib.request.urlopen(api_endpoint) 28 | 29 | content = resp.read() 30 | tree = ET.fromstring(content) 31 | post_tags = tree.findall('.//post') 32 | post_count = len(post_tags) 33 | for post_tag in post_tags: 34 | 35 | for photo_tag in post_tag.findall('.//photo-url'): 36 | if photo_tag.attrib['max-width'] == str(imgWidth): 37 | photoUrl = photo_tag.text 38 | photoUrls.append(photoUrl) 39 | 40 | splash = random.choice(photoUrls) 41 | 42 | if args['type'] == 'tag': 43 | imagetag = ''% (splash) 44 | elif args['type'] == 'background': 45 | imagetag = 'background: url("%s") no-repeat center center'% (splash) 46 | elif args['type'] == 'markdown': 47 | imagetag = '![](%s)'% (splash) 48 | else: 49 | imagetag = '%s'% (splash) 50 | 51 | for region in self.view.sel(): 52 | self.view.replace(edit, region, imagetag) 53 | 54 | class InsertUnsplashTagCommand(sublime_plugin.TextCommand): 55 | def run(self, edit): 56 | self.view.run_command('insert_unsplash', {'args':{'type':'tag'}}) 57 | 58 | class InsertUnsplashUrlCommand(sublime_plugin.TextCommand): 59 | def run(self, edit): 60 | self.view.run_command('insert_unsplash', {'args':{'type':'url'}}) 61 | 62 | class InsertUnsplashBackgroundCommand(sublime_plugin.TextCommand): 63 | def run(self, edit): 64 | self.view.run_command('insert_unsplash', {'args':{'type':'background'}}) 65 | 66 | class InsertUnsplashMarkdownCommand(sublime_plugin.TextCommand): 67 | def run(self, edit): 68 | self.view.run_command('insert_unsplash', {'args':{'type':'markdown'}}) --------------------------------------------------------------------------------