• Stars
    star
    34
  • Rank 734,865 (Top 16 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 2 years ago
  • Updated 10 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Unsplash random image generator and downloader

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.