DMarby / picsum-photos

Lorem Ipsum... but for photos.
https://picsum.photos
MIT License
2.21k stars 153 forks source link

Provide placeholder for missing images #59

Closed michaelhays closed 4 years ago

michaelhays commented 4 years ago

First, thanks for the excellent resource.

I'm using picsum.photos as a part of my testing/seeding to generate random images. When I generate seed data for my app, I store the URL for a resource (e.g. the avatar for a user) as a URL string in the database. Each resource should return the same image each time it's loaded, so storing https://picsum.photos/1200/800 directly wouldn't work, since it will return a different image each time you request the URL. Additionally, I'd also like to avoid making a request to retrieve a random deterministic image, so requesting https://picsum.photos/1200/800 to get the value of https://i.picsum.photos/id/223/1200/800.jpg is less than ideal.

My thought was to generate a random integer from 0-999 to find an image ID, like https://picsum.photos/id/#{rand(0...999)}/1200/800. But some image IDs don't exist in this range (Issue #53).

For my case, it would be a major improvement if an unknown/deleted image ID returned a placeholder image like https://placehold.co/, rather than responding with a 404 like it currently does. I'd guess this is likely true for most people using picsum.

What do you think? I can open a PR and work on this if you agree.

DMarby commented 4 years ago

Hi,

I would recommend using the seed endpoint, which was made for this exact case. It will give you the same image every time, based on whatever input you give it, so that should solve your use case. For example, you can use the username or the user ID as input. You can use it like so: https://picsum.photos/seed/{whatever}/200/300. More information about it is available on https://picsum.photos.

Not interested in supporting serving images for missing IDs, so I won't accept a PR implementing any functionality like that.

Let me know if you run into any issues/have any further questions.

michaelhays commented 4 years ago

Oof, no idea how I missed that endpoint. Thanks!