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,
  n = 1,
  w.px = 500,
  h.px = 500,
  ext = "jpg",
  paths = FALSE,
  cat = NULL
)

Arguments

fp

CHARACTER. storage directory

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

cat

CHARACTER. category of image to download

Value

downloaded image from a select image category

Sources & References

The random images are downloaded from https://picsum.photos

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); Note that cat will be deprecated in version 0.9

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(),n = 2)

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

# download 10 random images with extension png
genRandImg(fp = tempdir(),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.9.1 Index]