https://github.com/bomberstudios/sketch-image-downloader
A Sketch module to handle image downloads and insertion in documents
https://github.com/bomberstudios/sketch-image-downloader
Last synced: 4 months ago
JSON representation
A Sketch module to handle image downloads and insertion in documents
- Host: GitHub
- URL: https://github.com/bomberstudios/sketch-image-downloader
- Owner: bomberstudios
- License: mit
- Created: 2019-09-16T19:05:46.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2020-03-18T13:59:49.000Z (over 6 years ago)
- Last Synced: 2025-10-05T15:37:49.074Z (9 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# sketch-image-downloader
A Sketch module to handle image downloads and insertion in documents
## Usage
### `insertImage(url, parentLayer)`
Inserts a bitmap layer in `parentLayer` with the contents of the image at `url`.
Returns the image layer as a Promise, so you can chain the function.
```
import sketch from 'sketch'
import insertImage from 'sketch-image-downloader'
insertImage('https://source.unsplash.com/random', sketch.getSelectedDocument().selectedPage)
```
With promises:
```
import sketch from 'sketch'
import insertImage from 'sketch-image-downloader'
insertImage('https://source.unsplash.com/random', sketch.getSelectedDocument().selectedPage).then(layer => {
console.log(`Inserted layer: ${layer.name}`)
})
```
### `getImageFromURL(url)`
Downloads the image at `url` and returns a path to the local file, ready to use in your `DataProvider` plugins.
Returns the image path as a Promise, so you can chain the function.
```
import sketch from 'sketch'
import getImageFromURL from 'sketch-image-downloader'
getImageFromURL('https://source.unsplash.com/random')
```
With promises:
```
import sketch from 'sketch'
import getImageFromURL from 'sketch-image-downloader'
getImageFromURL('https://source.unsplash.com/random').then(path => {
console.log(`Image saved to ${path}`)
})
```