Requires curl, or allow_url_fopen to be on in php.ini.
public static image ( $dir = null, $width = 640, $height = 480, $category = null, $fullPath = true, $randomize = true, $word = null ) |
public function testDownloadWithDefaults() { $url = "http://www.lorempixel.com/"; $curlPing = curl_init($url); curl_setopt($curlPing, CURLOPT_TIMEOUT, 5); curl_setopt($curlPing, CURLOPT_CONNECTTIMEOUT, 5); curl_setopt($curlPing, CURLOPT_RETURNTRANSFER, true); $data = curl_exec($curlPing); $httpCode = curl_getinfo($curlPing, CURLINFO_HTTP_CODE); curl_close($curlPing); if ($httpCode < 200 | $httpCode > 300) { $this->markTestSkipped("LoremPixel is offline, skipping image download"); } $file = Image::image(sys_get_temp_dir()); $this->assertFileExists($file); if (function_exists('getimagesize')) { list($width, $height, $type, $attr) = getimagesize($file); $this->assertEquals(640, $width); $this->assertEquals(480, $height); $this->assertEquals(constant('IMAGETYPE_JPEG'), $type); } else { $this->assertEquals('jpg', pathinfo($file, PATHINFO_EXTENSION)); } if (file_exists($file)) { unlink($file); } }
public function testDownloadWithDefaults() { $file = Image::image(sys_get_temp_dir()); $this->assertFileExists($file); if (function_exists('getimagesize')) { list($width, $height, $type, $attr) = getimagesize($file); $this->assertEquals(640, $width); $this->assertEquals(480, $height); $this->assertEquals(constant('IMAGETYPE_JPEG'), $type); } else { $this->assertEquals('jpg', pathinfo($file, PATHINFO_EXTENSION)); } if (file_exists($file)) { unlink($file); } }
/** * @param $fakeDir * * @return string */ protected function createImage($fakeDir) { $faker = Faker\Factory::create('fr_FR'); $image = Faker\Provider\Image::image(); $result = sprintf("%s/image-%s.jpg", $fakeDir, $faker->slug(3)); rename($image, $result); return $result; }