PluginProbe
FakerPress / 0.8.0
FakerPress v0.8.0
0.9.2 trunk 0.1.0 0.1.1 0.1.2 0.1.3 0.5.2 0.5.3 0.6.1 0.6.2 0.6.3 0.6.4 0.6.5 0.6.6 0.7.0 0.7.1 0.7.2 0.8.0 0.9.0 0.9.1
fakerpress / src / FakerPress / Provider / Image / LoremPicsum.php

LoremPicsum.php in FakerPress 0.8.0, at src/FakerPress/Provider/Image/LoremPicsum.php

49 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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