Skip to content

Commit

Permalink
Merge pull request #5 from iMi-digital/fix/allow-resizing
Browse files Browse the repository at this point in the history
Disable most functions for SVGs, like resizing
  • Loading branch information
DanieliMi committed Aug 13, 2020
2 parents 8a4dead + 1d2b446 commit 4909565
Showing 1 changed file with 131 additions and 0 deletions.
131 changes: 131 additions & 0 deletions SVGImageMagickAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,135 @@ public function validateUploadFile($filePath)
}
return parent::validateUploadFile($filePath);
}

private function getNotImplementedMessage($method)
{
return sprintf(
'%s is intentionally not implemented for SVG files, processing is not believed not to be needed for SVGs. Filename = %s',
$method, $this->_fileName
);
}

/**
* We skip most logic for SVGs, as ImageMagick can not reliabily handle them on all systems, and things like
* resizing just don't make sense.
*
* Pull requests welcome, if needed, to improve this / make it configurable.
*
* @param $method
* @return bool
*/
private function skipForSvg($method)
{
if (!isset($this->_fileName)) {
return false;
}
if (strtolower(pathinfo($this->_fileName, PATHINFO_EXTENSION)) == 'svg' ){
$this->logger->debug($this->getNotImplementedMessage($method));

return true;
}
return false;
}

public function open($fileName)
{
$this->_fileName = $fileName;

if ($this->skipForSvg(__METHOD__)) {
return;
}

return parent::open($fileName);
}

public function save($destination = null, $newName = null)
{
if ($this->skipForSvg(__METHOD__)) {
return;
}

return parent::save($destination, $newName);
}

public function getImage()
{
if ($this->skipForSvg(__METHOD__)) {
return;
}

return parent::getImage();
}

public function resize($width = null, $height = null)
{
if ($this->skipForSvg(__METHOD__)) {
return;
}

return parent::resize($width, $height);
}

public function rotate($angle)
{
if ($this->skipForSvg(__METHOD__)) {
return;
}

return parent::rotate($angle);
}

public function crop($top = 0, $left = 0, $right = 0, $bottom = 0)
{
if ($this->skipForSvg(__METHOD__)) {
return;
}

return parent::crop($top, $left, $right, $bottom);
}

public function watermark($imagePath, $positionX = 0, $positionY = 0, $opacity = 30, $tile = false)
{
if ($this->skipForSvg(__METHOD__)) {
return;
}

return parent::watermark($imagePath, $positionX, $positionY, $opacity, $tile);
}

public function checkDependencies()
{
if ($this->skipForSvg(__METHOD__)) {
return;
}

parent::checkDependencies();
}

public function createPngFromString($text, $font = '')
{
if ($this->skipForSvg(__METHOD__)) {
return;
}

return parent::createPngFromString($text, $font);
}

public function refreshImageDimensions()
{
if ($this->skipForSvg(__METHOD__)) {
return;
}

return parent::refreshImageDimensions();
}

public function getColorAt($x, $y)
{
if ($this->skipForSvg(__METHOD__)) {
return;
}

return parent::getColorAt($x, $y);
}
}

0 comments on commit 4909565

Please sign in to comment.