/** * Test to see if we can determine the image format. * * @param string $data * * @return ImageFormat|null */ public function getImageFormat(&$data) { if (!$data || strlen($data) < 5) { return null; } // JPEG: FF D8 if (ord($data[0]) == 0xff && ord($data[1]) == 0xd8) { return ImageFormat::JPEG(); } // PNG: 89 50 4E 47 if (ord($data[0]) == 0x89 && substr($data, 1, 3) == 'PNG') { return ImageFormat::PNG(); } // GIF87a: 47 49 46 38 37 61 // GIF89a: 47 49 46 38 39 61 if (substr($data, 0, 6) == 'GIF87a' || substr($data, 0, 6) == 'GIF89a') { return ImageFormat::GIF(); } return null; }
/** * @medium */ public function testVariationRemoteCreate() { $fn = __DIR__ . '/../Resources/image.png'; $im = new ImageManager(new Filesystem(new LocalAdapter(static::$tmp_dir . 'remote'))); $source = $im->loadFromFile($fn, self::TEST_KEY_VAR); $im->push($source); $var = new ImageVariation(self::TEST_KEY_VAR, ImageFormat::GIF(), 50); $im->pull($var); $this->assertTrue($var->isHydrated()); $this->assertFalse($var->isPersistent()); $this->assertTrue($im->exists($source)); $this->assertFalse($im->exists($var)); $im->push($var); $this->assertTrue($var->isPersistent()); $this->assertTrue($im->exists($var)); }