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 / Placeholder.php

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

46 lines 1.2 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 /**
8 * @since 0.6.0
9 */
10 class Placeholder extends Base {
11 const ID = 'placeholder_image';
12
13 /**
14 * Generates a URL for Placeholder.com
15 *
16 * @since 0.1.5
17 * @since 0.4.9 On this version we started to accept Array or Int in the Second Param
18 *
19 * @param array|int $width A range for the images that will be generated, if a int is passed
20 * we use that value always.
21 * @param float|array|int $height Image height, int for fixed size, array for randomized and
22 * float to use a ratio
23 *
24 * @return string
25 */
26 public function placeholder_image( $width = [ 200, 640 ], $height = 1.25 ) {
27 if ( is_array( $width ) ){
28 $width = call_user_func_array( [ $this->generator, 'numberBetween' ], $width );
29 }
30
31 // Makes sure we have an Int
32 $width = absint( $width );
33
34 // Check For float (ratio)
35 if ( is_float( $height ) ) {
36 $height = floor( $width / floatval( $height ) );
37 } elseif ( is_array( $height ) ) {
38 $height = call_user_func_array( [ $this->generator, 'numberBetween' ], $height );
39 }
40
41 $url = "https://placehold.co/{$width}x{$height}/";
42
43 return $url;
44 }
45 }
46