public function testPng() { $file = __DIR__ . '/images/image.png'; $tmpFile = __DIR__ . '/images/tmp.' . static::$library . '.image.png'; $image = Image::create($file, static::$library); $this->assertSame('image/png', $image->getMimeType()); $this->assertSame(512, $image->getWidth()); $this->assertSame(512, $image->getHeight()); //Resize $image->resize(500); $this->assertSame(500, $image->getWidth()); $this->assertSame(500, $image->getHeight()); //Crop $image->crop(400, 300, Image::CROP_ENTROPY); $this->assertSame(400, $image->getWidth()); $this->assertSame(300, $image->getHeight()); $image->crop('50%', '50%'); $this->assertSame(200, $image->getWidth()); $this->assertSame(150, $image->getHeight()); //Save $image->save($tmpFile); $this->assertTrue(is_file($tmpFile)); $image = Image::create($tmpFile, static::$library); $this->assertSame(200, $image->getWidth()); $this->assertSame(150, $image->getHeight()); unlink($tmpFile); }
public function serve() { $imgPath = public_path() . Input::get(Config::get('image::vars.image')); $operations = Input::get(Config::get('image::vars.transform')); $checksum = md5($imgPath . ';' . serialize($operations)); $cacheData = $this->cache->get($checksum); if ($cacheData) { // using cache if (($string = $cacheData['data']) && ($mimetype = $cacheData['mime'])) { header('Content-Type: ' . $mimetype); die($string); } else { throw new \Exception('There was an error with the image cache'); } } else { $image = \Imagecow\Image::create($imgPath, Config::get('image::worker')); if ((int) Config::get('image::compression_quality')) { $image->setCompressionQuality(Config::get('image::compression_quality')); } $image->transform($operations); $cacheData = array('mime' => $image->getMimeType(), 'data' => $image->getString()); $this->cache->put($checksum, $cacheData, $this->cacheLifetime); $image->show(); // if the script didn't die then it will have an error (Imagecow::show() dies when it returns image data) throw new \Exception($image->getError()->getMessage()); } }
public function testIcon() { $file = __DIR__ . '/images/favicon.ico'; $tmpFile = __DIR__ . '/images/tmp.favicon.png'; $icon = new IconExtractor($file); $image = $icon->getBetterQuality(); $this->assertSame(256, $image->getWidth()); $this->assertSame(256, $image->getHeight()); //Save $image->save($tmpFile); $this->assertTrue(is_file($tmpFile)); $image = Image::create($tmpFile); $this->assertSame(256, $image->getWidth()); $this->assertSame(256, $image->getHeight()); }
/** * Register the image worker. * * @return void */ public function registerWorker() { $this->app['image.worker'] = $this->app->share(function ($app) { return Worker::create($app['config']->get('image::worker')); }); }
/** Convert tiff to jpeg * @access public * @param $image */ public function convertTiff() { $tiffDir = IMAGE_PATH . $this->getUserPath() . self::TIFFS; //Determine path to Tiff folder $tiffPath = $tiffDir . $this->getBasename() . self::EXT; //Where we will be saving the file $destination = $this->getUserPath(); //Check if directory exists, if not then make directory if (!is_dir($tiffDir)) { $this->_makeDirectory($tiffDir); } //Create an instance of the image to save $surrogate = Image::create($tiffPath, 'Imagick'); //Set the image to save as jpeg file $surrogate->format('jpg'); //Save to original folder as jpeg $surrogate->save($destination); //return to the resize function $this->resize(); }