From 434509d356b455d37339a0d2e76ef9dfb14400d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Kars=CC=A7=C4=B1yakal=C4=B1?= Date: Thu, 15 Jan 2015 03:53:01 +0200 Subject: [PATCH 1/2] added custom text argument --- readme.md | 1 + src/Faker/Provider/Image.php | 10 +++++++--- test/Faker/Provider/ImageTest.php | 5 +++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 222e8188a4..8a47d5d9c5 100644 --- a/readme.md +++ b/readme.md @@ -221,6 +221,7 @@ Each of the generator properties (like `name`, `address`, and `lorem`) are calle imageUrl($width, $height, 'cats') // 'http://lorempixel.com/800/600/cats/' image($dir = '/tmp', $width = 640, $height = 480) // '/tmp/13b73edae8443990be1aa8f1a483bc27.jpg' image($dir, $width, $height, 'cats') // 'tmp/13b73edae8443990be1aa8f1a483bc27.jpg' it's a cat! + image($dir, $width, $height, false, 'Faker') // 'http://lorempixel.com/800/400/nature/Faker' ### `Faker\Provider\Uuid` diff --git a/src/Faker/Provider/Image.php b/src/Faker/Provider/Image.php index e915ff474a..ce0548601f 100644 --- a/src/Faker/Provider/Image.php +++ b/src/Faker/Provider/Image.php @@ -19,7 +19,7 @@ class Image extends Base * * @example 'http://lorempixel.com/640/480/?12345' */ - public static function imageUrl($width = 640, $height = 480, $category = null, $randomize = true) + public static function imageUrl($width = 640, $height = 480, $category = null, $randomize = true, $word = null) { $url = "http://lorempixel.com/{$width}/{$height}/"; if ($category) { @@ -27,6 +27,10 @@ public static function imageUrl($width = 640, $height = 480, $category = null, $ throw new \InvalidArgumentException(sprintf('Unkown image category "%s"', $category)); } $url .= "{$category}/"; + + if ($word) { + $url .= "{$word}/"; + } } if ($randomize) { @@ -43,7 +47,7 @@ public static function imageUrl($width = 640, $height = 480, $category = null, $ * * @example '/path/to/dir/13b73edae8443990be1aa8f1a483bc27.jpg' */ - public static function image($dir = '/tmp', $width = 640, $height = 480, $category = null, $fullPath = true) + public static function image($dir = '/tmp', $width = 640, $height = 480, $category = null, $fullPath = true, $randomize = true, $word = null) { // Validate directory path if (!is_dir($dir) || !is_writable($dir)) { @@ -56,7 +60,7 @@ public static function image($dir = '/tmp', $width = 640, $height = 480, $catego $filename = $name .'.jpg'; $filepath = $dir . DIRECTORY_SEPARATOR . $filename; - $url = static::imageUrl($width, $height, $category); + $url = static::imageUrl($width, $height, $category, $randomize, $word); // save file if (function_exists('curl_exec')) { diff --git a/test/Faker/Provider/ImageTest.php b/test/Faker/Provider/ImageTest.php index 02f2d49071..0535d4daa7 100644 --- a/test/Faker/Provider/ImageTest.php +++ b/test/Faker/Provider/ImageTest.php @@ -21,6 +21,11 @@ public function testImageUrlAcceptsCustomCategory() $this->assertRegExp('#^http://lorempixel.com/800/400/nature/#', Image::imageUrl(800, 400, 'nature')); } + public function testImageUrlAcceptsCustomText() + { + $this->assertRegExp('#^http://lorempixel.com/800/400/nature/Faker#', Image::imageUrl(800, 400, 'nature', false, 'Faker')); + } + public function testImageUrlAddsARandomGetParameterByDefault() { $url = Image::imageUrl(800, 400); From 4cb8aa571f1fe1a2e763081b5472d99e2b9e5d4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emir=20Kar=C5=9F=C4=B1yakal=C4=B1?= Date: Thu, 15 Jan 2015 09:47:32 +0200 Subject: [PATCH 2/2] updated image section on readme.md --- readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 8a47d5d9c5..1c0c87d500 100644 --- a/readme.md +++ b/readme.md @@ -219,9 +219,10 @@ Each of the generator properties (like `name`, `address`, and `lorem`) are calle // Image generation provided by LoremPixel (http://lorempixel.com/) imageUrl($width = 640, $height = 480) // 'http://lorempixel.com/640/480/' imageUrl($width, $height, 'cats') // 'http://lorempixel.com/800/600/cats/' + imageUrl($width, $height, 'cats', false, 'Faker') // 'http://lorempixel.com/800/400/cats/Faker' image($dir = '/tmp', $width = 640, $height = 480) // '/tmp/13b73edae8443990be1aa8f1a483bc27.jpg' image($dir, $width, $height, 'cats') // 'tmp/13b73edae8443990be1aa8f1a483bc27.jpg' it's a cat! - image($dir, $width, $height, false, 'Faker') // 'http://lorempixel.com/800/400/nature/Faker' + image($dir, $width, $height, 'cats', false, 'Faker') // 'tmp/13b73edae8443990be1aa8f1a483bc27.jpg' it's a cat with Faker text ### `Faker\Provider\Uuid`