/** * 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 testLocalResample() { $fn = __DIR__ . '/../Resources/image.png'; $im = new ImageManager(new Filesystem(new LocalAdapter(static::$tmp_dir . 'remote'))); $source = $im->loadFromFile($fn, self::TEST_KEY_VAR); $resized = $im->createVariation($source, ImageFormat::JPEG(), 90, new ImageDimensions(100)); $this->assertTrue($resized->isHydrated()); $this->assertFalse($resized->isPersistent()); $im->save($resized, self::$tmp_dir . 'local/resized.jpg'); }