Wolfram Research

Function Repository Resource:

RandomPhoto

Source Notebook

Get random photographs of given sizes

Contributed by: Michael Sollami  |  Michael Sollami

ResourceFunction["RandomPhoto"][n]

gives a random square photograph of pixel dimension nn.

ResourceFunction["RandomPhoto"][w,h]

gives a random photograph of width w and height h.

Details and Options

ResourceFunction["RandomPhoto"] requires $NetworkConnected since it relies on a third party API Picsum (formerly Lorem Pixel)
You can find a list of all the available images at picsum.photos/images
ResourceFunction["RandomPhoto"] takes a the following options:
ColorSpace"RGB"the colorspace of the image; can be either "RGB" or "Grayscale"
"ImageID"Noneget a specific image from the database by providing an integer
"ImageType""JPEG"the type of image returned, which can be either JPEG or WEBP
"Seed"Noneget the same random image everytime based on an integer seed
The images returned by ResourceFunction["RandomPhoto"] may come with license restrictions.

Examples

Basic Examples (2) 

Get a random photo containing 200 squared pixels:

In[1]:=
ResourceFunction["RandomPhoto"][200]
Out[1]=

Get a random photo with arbitrary dimension:

In[2]:=
Labeled[img = ResourceFunction["RandomPhoto"][350, 250], img // ImageDimensions // Text , Top]
Out[2]=

Scope (2) 

Assemble an image out of multiple random photos:

In[3]:=
ImageAssemble[Table[ResourceFunction["RandomPhoto"][100, 100], 3, 4]]
Out[3]=

Get a random grayscale photograph with pixel dimension 400⨯200:

In[4]:=
ResourceFunction["RandomPhoto"][400, 247, ColorSpace -> "Grayscale"]
Out[4]=

Options (3) 

Request a random grayscale photograph:

In[5]:=
Labeled[img = ResourceFunction["RandomPhoto"][400, 200, ColorSpace -> "Grayscale"], img // ImageColorSpace // Text , Top]
Out[7]=

Retrieve the photo at index 472:

In[8]:=
ResourceFunction["RandomPhoto"][700, 200, "ImageID" -> 472]
Out[8]=

Specify an integer seed when getting random photos:

In[9]:=
Table[ResourceFunction["RandomPhoto"][250, "Seed" -> RandomInteger[{1, 100}]], 3] // List // Grid
Out[9]=

Observe that a given seed will return the same image:

In[10]:=
Table[Table[ResourceFunction["RandomPhoto"][250, "Seed" -> s], 3], {s, {1, 2, 3}}] // Grid
Out[10]=

Possible Issues (1) 

The requested dimensions need to be integers:

In[11]:=
ResourceFunction["RandomPhoto"][400, 400/N@GoldenRatio, ColorSpace -> "Grayscale"]
Out[11]=

Resource History

Related Resources

License Information