Beispiel #1
0
 /**
  * Process image resizing
  * 
  * @param  Image  $image
  * @return Image
  */
 protected function process(ImageCache $image)
 {
     switch ($this->getMode()) {
         case 'widen':
             return $image->widen($this->width);
             break;
         case 'heighten':
             return $image->heighten($this->height);
             break;
         case 'fit':
             return $image->fit($this->width, $this->height);
             break;
         default:
             return $image->resize($this->width, $this->height);
             break;
     }
 }
Beispiel #2
0
 public function testBinaryInput()
 {
     $data = file_get_contents(__DIR__.'/files/test.png');
     $img = new ImageCache;
     $img->make($data);
 }
Beispiel #3
0
 public function testOriginalFileChanged()
 {
     $filename = __DIR__ . '/files/foo.bar';
     // create tmp file
     touch($filename);
     // get original checksum
     $img = new ImageCache();
     $img->make($filename);
     $img->resize(300, 200);
     $checksum_original = $img->checksum();
     // get modified checksum
     clearstatcache();
     $modified = touch($filename, 10);
     // get modified checksum
     $img = new ImageCache();
     $img->make($filename);
     $img->resize(300, 200);
     $checksum_modified = $img->checksum();
     // delete tmp file
     unlink($filename);
     $this->assertTrue($modified);
     $this->assertNotEquals($checksum_original, $checksum_modified);
 }
 public function testGetImageNotFromCacheAsObject()
 {
     $lifetime = 12;
     $checksum = 'c6b782cdfd704596bf7cf8ee471b12f7';
     $imagedata = 'mocked image data';
     $image = Mockery::mock('\\Intervention\\Image\\Image');
     $image->shouldReceive('resize')->with(100, 150)->once()->andReturn($image);
     $image->shouldReceive('encode')->with()->once()->andReturn($imagedata);
     $manager = Mockery::mock('\\Intervention\\Image\\ImageManager');
     $manager->shouldReceive('make')->with('foo/bar.jpg')->once()->andReturn($image);
     $cache = Mockery::mock('\\Illuminate\\Cache\\Repository');
     $cache->shouldReceive('get')->with($checksum)->once()->andReturn(false);
     $cache->shouldReceive('put')->with($checksum, $imagedata, $lifetime)->once()->andReturn(false);
     $img = new ImageCache($manager, $cache);
     $img->make('foo/bar.jpg');
     $img->resize(100, 150);
     $result = $img->get($lifetime, true);
     $this->assertEquals($imagedata, $result);
 }