From 02107bc738466b32348734318c9c3824b5d4a472 Mon Sep 17 00:00:00 2001 From: Robert Reinhard Date: Fri, 23 Aug 2013 10:44:46 -0700 Subject: [PATCH] Image generation powered by LoremPixel --- readme.md | 18 +++++++ src/Faker/Provider/Image.php | 79 +++++++++++++++++++++++++++++++ test/Faker/Provider/ImageTest.php | 43 +++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 src/Faker/Provider/Image.php create mode 100644 test/Faker/Provider/ImageTest.php diff --git a/readme.md b/readme.md index d94181a6..9f291118 100644 --- a/readme.md +++ b/readme.md @@ -195,6 +195,7 @@ Each of the generator properties (like `name`, `address`, and `lorem`) are calle safeColorName // 'fuchsia' colorName // 'Gainsbor' +<<<<<<< HEAD ### `Faker\Provider\Payment` creditCardType // 'MasterCard' @@ -243,6 +244,23 @@ $faker->optional($weight = 0.9)->randomDigit; // 90% chance to get null // the default $weight value is 0.5 ``` +### `Faker\Provider\Image` + + 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' + imageUrl // 'http://lorempixel.com/1160/1160/' + imageUrl($width, $height) // 'http://lorempixel.com/800/600/' + imageUrl($width, $height, $category) // 'http://lorempixel.com/800/600/person/' + personImage($dir) // '/path/to/dir/13b73edae8443990be1aa8f1a483bc27.jpg' + personImageUrl // 'http://lorempixel.com/1160/1160/person/' + +Image generation is done by [LoremPixel](http://lorempixel.com/. Common params are: + +* $dir - An absolute path to a local directory +* $width/$height - Integer width and heigh values for the image you want generated +* $category - May be 'abstract', 'animals','business','cats','city','food','nightlife','fashion','people','nature','sports','technics','transport'. Singular forms of all are supported as well. + ## Localization `Faker\Factory` can take a locale as an argument, to return localized data. If no localized provider is found, the factory fallbacks to the default locale (en_EN). diff --git a/src/Faker/Provider/Image.php b/src/Faker/Provider/Image.php new file mode 100644 index 00000000..b0984eb3 --- /dev/null +++ b/src/Faker/Provider/Image.php @@ -0,0 +1,79 @@ +assertEquals(Image::imageUrl(), 'http://lorempixel.com/1160/1160/'); + } + + public function testUrlWithDimensions() + { + $this->assertEquals(Image::imageUrl(800, 400), 'http://lorempixel.com/800/400/'); + } + + public function testUrlWithDimensionsAndCategory() + { + $this->assertEquals(Image::imageUrl(800, 400, 'nature'), 'http://lorempixel.com/800/400/nature/'); + } + + public function testUrlWithDimensionsAndBadCategory() + { + $this->assertEquals(Image::imageUrl(800, 400, 'bullhonky'), 'http://lorempixel.com/800/400/'); + } + + public function testDownloadWithDefaults() { + $file = Image::image('/tmp'); + $this->assertFileExists($file); + if (file_exists($file)) unlink($file); + } + + public function testMagicCategory() { + $this->assertEquals(Image::peopleImageUrl(800, 400, 'nature'), 'http://lorempixel.com/800/400/nature/'); + // $faker = \Faker\Factory::create(); + // $this->assertEquals(Image::peopleImageUrl(800, 400, 'nature'), 'http://lorempixel.com/800/400/nature/'); + + } + +}