setBlob() public method

Set the blob and update filesize and checksum properties
public setBlob ( string $blob ) : Image
$blob string The binary data to set
return Image
Esempio n. 1
0
 /**
  * @covers Imbo\Model\Image::setBlob
  * @covers Imbo\Model\Image::getBlob
  * @covers Imbo\Model\Image::getFilesize
  * @covers Imbo\Model\Image::setFilesize
  * @covers Imbo\Model\Image::getChecksum
  * @covers Imbo\Model\Image::setChecksum
  */
 public function testCanSetAndGetBlob()
 {
     $blob = 'some string';
     $hash = md5($blob);
     $this->assertSame($this->image, $this->image->setBlob($blob));
     $this->assertSame($blob, $this->image->getBlob());
     $this->assertSame(11, $this->image->getFilesize());
     $this->assertSame($hash, $this->image->getChecksum());
     $blob = 'some other string';
     $hash = md5($blob);
     $this->assertSame($this->image, $this->image->setBlob($blob));
     $this->assertSame($blob, $this->image->getBlob());
     $this->assertSame(17, $this->image->getFilesize());
     $this->assertSame($hash, $this->image->getChecksum());
 }
Esempio n. 2
0
 /**
  * @dataProvider getParamsForWatermarks
  * @covers Imbo\Image\Transformation\Watermark::transform
  */
 public function testApplyToImageTopLeftWithOnlyWidthAndDefaultWatermark($params, $colors)
 {
     $blob = file_get_contents(FIXTURES_DIR . '/white.png');
     $image = new Image();
     $image->setBlob($blob);
     $image->setWidth($this->width);
     $image->setHeight($this->height);
     $transformation = $this->getTransformation();
     $transformation->setDefaultImage($this->watermarkImg);
     $expectedWatermark = $this->watermarkImg;
     if (isset($params['img'])) {
         $expectedWatermark = $params['img'];
     }
     $storage = $this->getMock('Imbo\\Storage\\StorageInterface');
     $storage->expects($this->once())->method('getImage')->with('someUser', $expectedWatermark)->will($this->returnValue(file_get_contents(FIXTURES_DIR . '/black.png')));
     $request = $this->getMock('Imbo\\Http\\Request\\Request');
     $request->expects($this->once())->method('getUser')->will($this->returnValue('someUser'));
     $event = new Event();
     $event->setArguments(['image' => $image, 'params' => $params, 'storage' => $storage, 'request' => $request]);
     $imagick = new Imagick();
     $imagick->readImageBlob($blob);
     $transformation->setImagick($imagick)->transform($event);
     foreach ($colors as $c) {
         $this->verifyColor($imagick, $c['x'], $c['y'], $c['colors']);
     }
 }
Esempio n. 3
0
 /**
  * @covers Imbo\EventListener\ExifMetadata::__construct
  * @covers Imbo\EventListener\ExifMetadata::populate
  * @covers Imbo\EventListener\ExifMetadata::save
  */
 public function testCanGetAndSaveProperties()
 {
     $listener = new ExifMetadata();
     $publicKey = 'foobar';
     $image = new Image();
     $image->setBlob(file_get_contents(FIXTURES_DIR . '/exif-logo.jpg'));
     $request = $this->getMock('Imbo\\Http\\Request\\Request');
     $request->expects($this->exactly(2))->method('getImage')->will($this->returnValue($image));
     $request->expects($this->once())->method('getPublicKey')->will($this->returnValue($publicKey));
     $database = $this->getMock('Imbo\\Database\\DatabaseInterface');
     $database->expects($this->once())->method('updateMetadata')->with($this->equalTo($publicKey), $this->equalTo('753e11e00522ff1e95600d8f91c74e8e'), $this->arrayHasKey('gps:location'));
     $event = $this->getMock('Imbo\\EventManager\\Event');
     $event->expects($this->exactly(2))->method('getRequest')->will($this->returnValue($request));
     $event->expects($this->once())->method('getDatabase')->will($this->returnValue($database));
     $properties = $listener->populate($event);
     $this->assertSame('SAMSUNG', $properties['exif:Make']);
     $this->assertSame('GT-I9100', $properties['exif:Model']);
     $listener->save($event);
 }