1
0
mirror of https://github.com/fzaninotto/Faker.git synced 2025-03-24 09:19:50 +01:00

Merge pull request #274 from stefanosala/feature/fullpath

Added fullPath parameter to Image provider
This commit is contained in:
Francois Zaninotto 2014-03-11 09:25:24 +01:00
commit 6504aec265
2 changed files with 6 additions and 3 deletions

View File

@ -218,10 +218,12 @@ Each of the generator properties (like `name`, `address`, and `lorem`) are calle
* @param $dir An absolute path to a local directory
* @param $width/$height Size (in pixel) of the generated image (defaults to 640x480)
* @param $category One of 'abstract','animals','business','cats','city','food','nightlife','fashion','people','nature','sports','technics', and 'transport'
* @param $fullPath Whether to have the full path to the image or just the filename (default true)
*/
image($dir) // '/path/to/dir/13b73edae8443990be1aa8f1a483bc27.jpg'
image($dir, $width, $height) // '/path/to/dir/13b73edae8443990be1aa8f1a483bc27.jpg'
image($dir, $width, $height, $category) // '/path/to/dir/13b73edae8443990be1aa8f1a483bc27.jpg'
image($dir, $width, $height, $category, $fullPath = false) // '13b73edae8443990be1aa8f1a483bc27.jpg'
imageUrl // 'http://lorempixel.com/640/480/'
imageUrl($width, $height) // 'http://lorempixel.com/800/600/'
imageUrl($width, $height, $category) // 'http://lorempixel.com/800/600/person/'

View File

@ -37,7 +37,7 @@ class Image extends Base
*
* @example '/path/to/dir/13b73edae8443990be1aa8f1a483bc27.jpg'
*/
public static function image($dir = '/tmp', $width = 640, $height = 480, $category = null)
public static function image($dir = '/tmp', $width = 640, $height = 480, $category = null, $fullPath = true)
{
// Validate directory path
if (!is_dir($dir) || !is_writable($dir)) {
@ -47,7 +47,8 @@ class Image extends Base
// Generate a random filename. Use the server address so that a file
// generated at the same time on a different server won't have a collision.
$name = md5(uniqid(empty($_SERVER['SERVER_ADDR']) ? '' : $_SERVER['SERVER_ADDR'], true));
$filepath = $dir . DIRECTORY_SEPARATOR . $name .'.jpg';
$filename = $name .'.jpg';
$filepath = $dir . DIRECTORY_SEPARATOR . $filename;
$url = static::imageUrl($width, $height, $category);
@ -72,6 +73,6 @@ class Image extends Base
return false;
}
return $filepath;
return $fullPath ? $filepath : $filename;
}
}