| 1 |
<?php |
| 2 |
namespace FakerPress\Provider\Image; |
| 3 |
|
| 4 |
use FakerPress\ThirdParty\Faker\Provider\Base; |
| 5 |
|
| 6 |
/** |
| 7 |
* @since 0.4.2 |
| 8 |
* @since 0.5.0 Unsplash.it turned into Lorem Picsum |
| 9 |
*/ |
| 10 |
class LoremPicsum extends Base { |
| 11 |
const ID = 'lorempicsum'; |
| 12 |
|
| 13 |
/** |
| 14 |
* Generates a URL for Lorem Picsum, previosuly known as Unsplash.it |
| 15 |
* |
| 16 |
* @since 0.4.2 |
| 17 |
* @since 0.4.9 On this version we started to accept Array or Int in the Second Param |
| 18 |
* @since 0.5.0 Moved from Unsplash.it to Lorem Picsum |
| 19 |
* |
| 20 |
* @param array|int $width A range for the images that will be generated, if an int is passed |
| 21 |
* we use that value always. |
| 22 |
* @param float|array|int $height Image height, int for fixed size, array for randomized and |
| 23 |
* float to use a ratio |
| 24 |
* |
| 25 |
* @return string |
| 26 |
*/ |
| 27 |
public function lorempicsum( $width = [ 800, 1440 ], $height = 1.25 ) { |
| 28 |
if ( is_array( $width ) ){ |
| 29 |
$width = call_user_func_array( [ $this->generator, 'numberBetween' ], $width ); |
| 30 |
} |
| 31 |
|
| 32 |
// Makes sure we have an Int |
| 33 |
$width = absint( $width ); |
| 34 |
|
| 35 |
// Check For float (ratio) |
| 36 |
if ( is_float( $height ) ) { |
| 37 |
$height = floor( $width / floatval( $height ) ); |
| 38 |
} elseif ( is_array( $height ) ) { |
| 39 |
$height = call_user_func_array( [ $this->generator, 'numberBetween' ], $height ); |
| 40 |
} |
| 41 |
|
| 42 |
// https://picsum.photos/200/640/?random |
| 43 |
$url = "https://picsum.photos/{$width}/{$height}/?random"; |
| 44 |
|
| 45 |
return $url; |
| 46 |
} |
| 47 |
|
| 48 |
} |
| 49 |
|