Last active
September 3, 2022 14:14
-
-
Save mikemix/781d8f4b9d08409f76fdbb85cae52b5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
final class RandomImageSource implements ImageSourceInterface | |
{ | |
/** {@inheritDoc} */ | |
public function __invoke(string $imageId, string $imageFormat): ImageInterface | |
{ | |
return new ImmutableImage($imageId, $imageFormat, static function () use ($imageId): string { | |
$randomImageUrl = \sprintf('https://picsum.photos/seed/%s/1000/1000', \sha1($imageId)); | |
$randomImageData = \file_get_contents($randomImageUrl); | |
if (!$randomImageData) { | |
throw new ImageSourceException('Could not download the image'); | |
} | |
return $randomImageData; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment