/** * {@inheritdoc} */ public function insertImage($publicKey, $imageIdentifier, Image $image) { $now = time(); if ($added = $image->getAddedDate()) { $added = $added->getTimestamp(); } if ($updated = $image->getUpdatedDate()) { $updated = $updated->getTimestamp(); } if ($id = $this->getImageId($publicKey, $imageIdentifier)) { return (bool) $this->getConnection()->update($this->tableNames['imageinfo'], array('updated' => $now), array('id' => $id)); } return (bool) $this->getConnection()->insert($this->tableNames['imageinfo'], array('size' => $image->getFilesize(), 'publicKey' => $publicKey, 'imageIdentifier' => $imageIdentifier, 'extension' => $image->getExtension(), 'mime' => $image->getMimeType(), 'added' => $added ?: $now, 'updated' => $updated ?: $now, 'width' => $image->getWidth(), 'height' => $image->getHeight(), 'checksum' => $image->getChecksum(), 'originalChecksum' => $image->getOriginalChecksum())); }
/** * {@inheritdoc} */ public function insertImage($publicKey, $imageIdentifier, Image $image) { $now = time(); if ($added = $image->getAddedDate()) { $added = $added->getTimestamp(); } if ($updated = $image->getUpdatedDate()) { $updated = $updated->getTimestamp(); } if ($this->imageExists($publicKey, $imageIdentifier)) { try { $this->getImageCollection()->update(['publicKey' => $publicKey, 'imageIdentifier' => $imageIdentifier], ['$set' => ['updated' => $now]], ['multiple' => false]); return true; } catch (MongoException $e) { throw new DatabaseException('Unable to save image data', 500, $e); } } $data = ['size' => $image->getFilesize(), 'publicKey' => $publicKey, 'imageIdentifier' => $imageIdentifier, 'extension' => $image->getExtension(), 'mime' => $image->getMimeType(), 'metadata' => [], 'added' => $added ?: $now, 'updated' => $updated ?: $now, 'width' => $image->getWidth(), 'height' => $image->getHeight(), 'checksum' => $image->getChecksum(), 'originalChecksum' => $image->getOriginalChecksum()]; try { $this->getImageCollection()->insert($data); } catch (MongoException $e) { throw new DatabaseException('Unable to save image data', 500, $e); } return true; }
/** * @covers Imbo\Model\Image::setExtension * @covers Imbo\Model\Image::getExtension */ public function testCanSetAndGetExtension() { $extension = 'png'; $this->assertSame($this->image, $this->image->setExtension($extension)); $this->assertSame($extension, $this->image->getExtension()); }
/** * Expand the image so that we can fit the width and height of the borders specified on each * side, than copy the original image to the center of the canvas. * * @param string $color * @param integer $borderWidth * @param integer $borderHeight * @param Image $image */ private function expandImage($color, $borderWidth, $borderHeight, Image $image) { $imageWidth = $image->getWidth(); $imageHeight = $image->getHeight(); $original = clone $this->imagick; // Clear the original and make the canvas $this->imagick->clear(); $this->imagick->newImage($imageWidth + $borderWidth * 2, $imageHeight + $borderHeight * 2, $color); $this->imagick->setImageAlphaChannel(Imagick::ALPHACHANNEL_OPAQUE); $this->imagick->setImageFormat($image->getExtension()); $this->imagick->compositeImage($original, Imagick::COMPOSITE_COPY, $borderWidth, $borderHeight); }