A CLI and a set of Rails helpers to get free images from Unsplash.
This is the easiest way to fill your Rails app with real photos.
- as Rails helper to generate dummy images:
<%= image_tag unsplash_image_url(size: '300x200', tags: 'cat, dog') %>
<%= image_tag unsplash_image_url(size: '800x600', tags: 'building') %>
<%= image_tag unsplash_image_url(tags: 'nature') %>
- as a tool to download images from Unsplash.com and use them for your seeds or specs.
unsplash_image download --path images/cats --tags cat -n 20
- If you need to have a
File
object with a random image.
file = UnsplashImage.tempfile(size: '500x500', tags: 'cat')
By default unsplash_image download --path ./files
will download 10 random images into a ./files
folder.
You can see list of all available options by running:
unsplash_image --help download
With additional options you can specify a destination folder, tags, resolution of the images.
You can get random image url inside your views using unsplash_image_url
.
Example:
<%= image_tag unsplash_image_url(size: '300x200', tags: 'cat, dog') %>
Also you can get it as a file with UnsplashImage.tempfile
.
Example:
file = UnsplashImage.tempfile(size: '500x500', tags: 'cat')
Add this line to your application's Gemfile:
gem "unsplash_image"
And then execute:
$ bundle
To use CLI anywhere in the system you can install gem globally:
gem install unsplash_image
We have simple tests, just run: ruby test/unsplash_image_test.rb
.
You are welcome to contribute. See list of TODO's
below.
- allow caching downloaded files for performance improvement (eg using in factories)
- check with older Rails versions
- tests or specs
- make stand-alone executable installable via
brew
,apt get
, etc?
The gem is available as open source under the terms of the MIT License.