| 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 |
|