/home/techb158/immovalet.com/platform/core/media/src/Services
Edit: /home/techb158/immovalet.com/platform/core/media/src/Services/ThumbnailService.php (4426B)
thumbRate = 0.75;
$this->xCoordinate = null;
$this->yCoordinate = null;
$this->fitPosition = 'center';
$driver = 'gd';
if (extension_loaded('imagick')) {
$driver = 'imagick';
}
$this->imageManager = $imageManager->configure(compact('driver'));
$this->uploadManager = $uploadManager;
}
/**
* @param string $imagePath
* @return ThumbnailService
*/
public function setImage($imagePath)
{
$this->imagePath = $imagePath;
return $this;
}
/**
* @return string
*/
public function getImage()
{
return $this->imagePath;
}
/**
* @param int $width
* @param int $height
* @return ThumbnailService
*/
public function setSize($width, $height = null)
{
$this->thumbWidth = $width;
$this->thumbHeight = $height;
if (empty($height)) {
$this->thumbHeight = $this->thumbWidth * $this->thumbRate;
}
return $this;
}
/**
* @return array
*/
public function getSize()
{
return [$this->thumbWidth, $this->thumbHeight];
}
/**
* @param string $destinationPath
* @return ThumbnailService
*/
public function setDestinationPath($destinationPath)
{
$this->destinationPath = $destinationPath;
return $this;
}
/**
* @param int $xCoordination
* @param int $yCoordination
* @return ThumbnailService
*/
public function setCoordinates($xCoordination, $yCoordination)
{
$this->xCoordinate = $xCoordination;
$this->yCoordinate = $yCoordination;
return $this;
}
/**
* @return array
*/
public function getCoordinates()
{
return [$this->xCoordinate, $this->yCoordinate];
}
/**
* @param string $fileName
* @return ThumbnailService
*/
public function setFileName($fileName)
{
$this->fileName = $fileName;
return $this;
}
/**
* @return string
*/
public function getFileName()
{
return $this->fileName;
}
/**
* @param string $type
* @return bool|string
*/
public function save($type = 'fit')
{
$fileName = pathinfo($this->imagePath, PATHINFO_BASENAME);
if ($this->fileName) {
$fileName = $this->fileName;
}
$destinationPath = sprintf('%s/%s', trim($this->destinationPath, '/'), $fileName);
$thumbImage = $this->imageManager->make($this->imagePath);
switch ($type) {
case 'resize':
$thumbImage->resize($this->thumbWidth, $this->thumbHeight);
break;
case 'crop':
$thumbImage->crop($this->thumbWidth, $this->thumbHeight, $this->xCoordinate, $this->yCoordinate);
break;
case 'fit':
$thumbImage->fit($this->thumbWidth, $this->thumbHeight, null, $this->fitPosition);
}
try {
$this->uploadManager->saveFile($destinationPath, $thumbImage->stream()->__toString());
} catch (Exception $exception) {
Log::error($exception->getMessage());
return false;
}
return $destinationPath;
}
}