• This repository has been archived on 15/Jan/2019
  • Stars
    star
    176
  • Rank 210,495 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 6 years ago

Reviews

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

Repository Details

๐Ÿฎ A javascript wrapper for the Unsplash Source API

Unsplash Source JS

A javascript wrapper for the Unsplash Source API. Get random Unsplash photos by keyword, location, category, user, or ID.

Codeship Status for CrewLabs/unsplash-source-js

Usage

Include unsplash-source.js or unsplash-source.min.js in your page:

<script src="/js/unsplash-source.js"></script>

Then create the photo you want using any of the chainable methods below, calling fetch as the last step to return the photo's URL.

Method Arguments Example Description
find "publicId" photo.find("oMpAz-DN-9I") Finds a photo by its ID
width width photo.width(2000) Sets the width in pixels
height height photo.height(2000) Sets the height in pixels
size width, height photo.size(1080,800) Shorthand for setting the width and height in pixels
randomize `null "daily"
fromUser "username" photo.fromUser("erondu") Limits to a specific photographer
fromCategory "category" photo.fromCategory("nature") Limits to a specific category
of `"keyword" [arrayOfKeywords]`
all photo.all() Searches for all photos, instead of just featured photos
fetch photo.fetch() Returns the configured URL.

By default, the photos are filtered to featured photos. To remove this filter, call all. We recommend using all when limiting photos to a specific keyword (using of) or limiting photos to specific photographers (using fromUser) to maximize the possiblity of a matching photo.

Resize operations (width, height, size) maintain the aspect ratio of the original photo by cropping if necessary.

Note: Not all methods are compatible with each other. For example, trying to randomize a specific photo doesn't make sense. The wrapper will ignore incompatible methods and only construct URLs compatible with the Unsplash Source API.

Examples

Get a random photo (the Unsplash Source API defaults to a width of 1080px):

var photo = new UnsplashPhoto();

photo.fetch(); // => "https://source.unsplash.com/random"

Get a random featured photo that rotates weekly, cropped to 800px x 600px:

var photo = new UnsplashPhoto();

photo.randomize("weekly")
     .size(800, 600)
     .fetch(); // => "https://source.unsplash.com/800x600/weekly"

Get a random photo from photographer Jared Erondu cropped to 2048px x 1200px, that changes once a day:

var photo = new UnsplashPhoto();

photo.all()
     .fromUser("erondu")
     .width(2048)
     .height(1200)
     .randomize("daily")
     .fetch(); // => "https://source.unsplash.com/user/erondu/2048x1200/daily"

Get a random nature photo of trees and water from the 'all' feed, cropped to 1000px x 1200px:

var photo = new UnsplashPhoto();

photo.all()
     .fromCategory("nature")
     .of(["trees", "water"])
     .size(1000, 1200)
     .fetch(); // => "https://source.unsplash.com/category/nature/1000x1200?trees,water"

Get a specific photo (the photo ID matches the photo ID from unsplash.com):

photo = new UnsplashPhoto();

photo.find("oMpAz-DN-9I")
     .fetch(); // => "https://source.unsplash.com/oMpAz-DN-9I"

Development

To contribute, make sure Node and NPM are installed. Then:

git clone ..

npm install
grunt test // => should all pass

// make your changes to the `/src` folder
// add tests to `/tests`

grunt test // => should all pass

grunt build // => creates a bundled version of the script

git commit ..

More Repositories

1

react-trend

๐Ÿ“ˆ Simple, elegant spark lines
JavaScript
2,462
star
2

datasets

๐ŸŽ 4,800,000+ Unsplash images made available for research and machine learning
Jupyter Notebook
2,224
star
3

unsplash-js

๐Ÿค– Official JavaScript wrapper for the Unsplash API
TypeScript
2,027
star
4

unsplash-php

๐Ÿ‘ป Official PHP wrapper for the Unsplash API
PHP
405
star
5

unsplash-photopicker-ios

๐Ÿ“ฑAn iOS photo picker to search and download photos from Unsplash.
Swift
390
star
6

unsplash-photopicker-android

๐Ÿ“ฑAn Android photo picker to search and download photos from Unsplash.
Kotlin
327
star
7

unsplash_rb

๐Ÿ’Ž Ruby wrapper for the Unsplash API.
Ruby
224
star
8

comment-on-pr

A GitHub Action to comment on the relevant open PR when a commit is pushed.
Ruby
146
star
9

swiftui-lazycollectionview

A modest attempt to port UICollectionView to SwiftUI.
Swift
136
star
10

react-progressive-enhancement

A handy collection of HOCs for universally renderedย apps
TypeScript
63
star
11

intlc

Compile ICU messages into code. Supports TypeScript and JSX. No runtime.
Haskell
51
star
12

uploader-prototype

An open-source prototype of the Unsplash uploader.
TypeScript
45
star
13

sum-types

Safe, ergonomic, non-generic sum types in TypeScript.
TypeScript
41
star
14

url-transformers

Small helper library for manipulating URL strings in Node and in the browser.
TypeScript
35
star
15

ts-imgix

Strongly-typed imgix URL builder function, `buildImgixUrl`.
TypeScript
32
star
16

ts-namespace-import-plugin

Auto import common namespaces in your modules
TypeScript
30
star
17

pipe-ts

TypeScript
30
star
18

request-frp

`request-frp` is a package that provides pure wrappers around `fetch` and `XMLHttpRequest`.
TypeScript
14
star
19

ts-redux-finite-state-machine-example

TypeScript
13
star
20

tinplate

โญ๏ธ TinEye API wrapper
Ruby
13
star
21

responsive-image-test

TypeScript
12
star
22

unsplash-imageview-ios

A UIImageView subclass that displays a random photo from Unsplash.
Swift
9
star
23

imagga-auto-tag

๐ŸŽฉ Ruby client for fetching tags from the Imagga Auto Tagging API
Ruby
8
star
24

sum-types-fast-check

fast-check bindings for @unsplash/sum-types.
TypeScript
3
star
25

service-dash

๐Ÿ”ฅ Is anything on fire?
Ruby
2
star
26

swift-storyboard-identifiers

A script that generates identifiers strings from .storyboard files.
Ruby
2
star
27

mercury

The guide of souls to the underworld.
Rust
2
star
28

imgix-trackable

๐Ÿ›ฐ Tracklable Imgix URLs via the ixid param
TypeScript
2
star
29

sum-types-io-ts

io-ts bindings for @unsplash/sum-types.
TypeScript
2
star
30

ts-type-tests-example

TypeScript
2
star
31

import-sort-style-unsplash

TypeScript
2
star
32

sum-types-fp-ts

fp-ts bindings for @unsplash/sum-types.
TypeScript
2
star