0.01
No release in over a year
Show the random images in your Rails app or download them to use for seeding a DB
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0
>= 0

Runtime

>= 0.20
 Project Readme

Unsplash Image Downloader & Helpers

RailsJazz Listed on OpenSource-Heroes.com

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.

Usage

  1. 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') %>
  1. 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
  1. If you need to have a File object with a random image.
file = UnsplashImage.tempfile(size: '500x500', tags: 'cat')

CLI

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.

In your Rails app

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')

Installation

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

Unit Tests

We have simple tests, just run: ruby test/unsplash_image_test.rb.

Contributing

You are welcome to contribute. See list of TODO's below.

TODO

  • 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?

License

The gem is available as open source under the terms of the MIT License.