public function __toString() { if ($this->isSkip) { return ''; } $methodsHash = md5(serialize($this->methods)); $hash = md5($this->fileHash . $methodsHash); $source = 'storage/cropp/' . $hash . $this->extension; if (is_readable(public_path($source))) { return $source; } $image = Image::make($this->source); foreach ($this->methods as $method) { call_user_func_array(array($image, $method['name']), $method['arguments']); } $res = $image->save(public_path($source)); if (!$res) { throw new RuntimeException('Do you have writeable [public/storage/cropp/] directory?'); } if (\Config::get('jarboe::cropp.is_optimize')) { $optimizer = new \Extlib\ImageOptimizer(array(\Extlib\ImageOptimizer::OPTIMIZER_OPTIPNG => \Config::get('jarboe::cropp.binaries.optipng'), \Extlib\ImageOptimizer::OPTIMIZER_JPEGOPTIM => \Config::get('jarboe::cropp.binaries.jpegoptim'), \Extlib\ImageOptimizer::OPTIMIZER_GIFSICLE => \Config::get('jarboe::cropp.binaries.gifsicle'))); $optimizer->optimize(public_path($source)); } return $source; }
/** * Tests method * * @dataProvider files */ public function tests($file, $expected) { $optimizer = new \Extlib\ImageOptimizer(); $this->assertEquals($expected, $optimizer->optimize($file)); }