genRandImg {quickcode}R Documentation

Download random images from the web

Description

Generate n number of high-definition images by category from the web

Usage

genRandImg(
  fp,
  cat = imageCategories,
  n = 1,
  w.px = 500,
  h.px = 500,
  ext = "jpg",
  paths = FALSE
)

Arguments

fp

CHARACTER. storage directory

cat

CHARACTER. category of image to download

n

NUMERIC. number of images to download, maximum n is 99

w.px

NUMERIC. width in pixels

h.px

NUMERIC. height in pixels

ext

CHARACTER. file extension eg jpg, png

paths

logical. whether to return paths

Value

downloaded image from a select image category

Sources & References

The random images are downloaded from www.unsplash.com

Category Choices

Categories for 'cat' argument include "3D", "animals", "architecture", "backgrounds", "beauty", "experimental", "fashion", "film", "food", "interior", "nature", "people", "renders", "school", "sports", "travel", "unsplash", "wallpapers".

Image categories can be captured in a separate vector as a cross-reference made available to the cat argument.
For example:
imgcat= c("3D", "animals", "architecture", "backgrounds", "beauty", "experimental", "fashion", "film", "food", "interior", "nature", "people", "renders", "school", "sports", "travel", "unsplash", "wallpapers")

genRandImg(fp, cat = imgcat[9], n = 5)

Use case

This functionality is great for developers trying to obtain one or more images for use in displays/analysis or simply to build robust web applications.

Examples


# download 2 image from the nature category
genRandImg(fp = tempdir(),cat = "nature", n = 2)

# download 4 random images with width = 600px and hight 100px
genRandImg(
  fp = tempdir(),
  cat = "fashion",
  w.px = 600,
  h.px = 100)

# download 10 random images with extension png
genRandImg(fp = tempdir(),cat = "food", n = 10, ext = "png")


# download 200 random images from category of school
# Note that maximum download is 99, so the function will only download 99
genRandImg(fp = tempdir(),cat = "school", n = 200)

# download 5 random images with extension jif and return paths
genRandImg(fp = tempdir(),cat = "beauty", n = 5, ext = "jif", paths = TRUE)


[Package quickcode version 0.8 Index]