: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$ani = ($img->getNumberImages() > 1);
if ($ani && is_null($destformat)) {
$img = $img->coalesceImages();
$img->setImagePage($s[0], $s[1], 0, 0);
$img->cropImage($width, $height, $x, $y);
$img->setImagePage($width, $height, 0, 0);
} while ($img->nextImage());
$img->optimizeImageLayers();
$result = $img->writeImages($path, true);
$img->setFirstIterator();
$img->setImagePage($s[0], $s[1], 0, 0);
$img->cropImage($width, $height, $x, $y);
$img->setImagePage($width, $height, 0, 0);
$result = $this->imagickImage($img, $path, $destformat, $jpgQuality);
return $result ? $path : false;
extract($this->imageMagickConvertPrepare($path, $destformat, $jpgQuality, $s));
* @var string $deconstruct
* @var string $jpgQuality
* @var string $quotedPath
* @var string $quotedDstPath
$cmd = sprintf('%s %s%s%s%s -crop %dx%d+%d+%d%s %s', ELFINDER_CONVERT_PATH, $quotedPath, $coalesce, $jpgQuality, $interlace, $width, $height, $x, $y, $deconstruct, $quotedDstPath);
if ($this->procExec($cmd) === 0) {
return $result ? $path : false;
elFinder::expandMemoryForGD(array($s, array($width, $height)));
$img = $this->gdImageCreate($path, $s['mime']);
if ($img && false != ($tmp = imagecreatetruecolor($width, $height))) {
if ($s[2] === IMAGETYPE_GIF && (!$destformat || $destformat === 'gif')) {
$bgIdx = imagecolortransparent($img);
$c = imagecolorsforindex($img, $bgIdx);
$bgNum = imagecolorallocate($tmp, $c['red'], $c['green'], $c['blue']);
imagefill($tmp, 0, 0, $bgNum);
imagecolortransparent($tmp, $bgNum);
$this->gdImageBackground($tmp, 'transparent');
if ($s[0] < $width || $s[1] < $height) {
if (!imagecopy($tmp, $img, 0, 0, $x, $y, $size_w, $size_h)) {
$result = $this->gdImage($tmp, $path, $destformat, $s['mime'], $jpgQuality);
return $result ? $path : false;
* @param string $path image file
* @param int $width square width
* @param int $height square height
* @param int|string $align reserved
* @param int|string $valign reserved
* @param string $bgcolor square background color in #rrggbb format
* @param string $destformat image destination format
* @param int $jpgQuality JEPG quality (1-100)
* @throws ImagickException
* @throws elFinderAbortException
* @author Dmitry (dio) Levashov
* @author Alexey Sukhotin
protected function imgSquareFit($path, $width, $height, $align = 'center', $valign = 'middle', $bgcolor = '#0000ff', $destformat = null, $jpgQuality = null)
if (($s = getimagesize($path)) == false) {
/* Coordinates for image over square aligning */
$y = ceil(abs($height - $s[1]) / 2);
$x = ceil(abs($width - $s[0]) / 2);
$jpgQuality = $this->options['jpgQuality'];
elFinder::extendTimeLimit(300);
$img = new imagick($path);
if ($bgcolor === 'transparent') {
$bgcolor = 'rgba(255, 255, 255, 0.0)';
$ani = ($img->getNumberImages() > 1);
if ($ani && is_null($destformat)) {
$img = $img->coalesceImages();
$gif->newImage($width, $height, new ImagickPixel($bgcolor));
$gif->setImageColorspace($img->getImageColorspace());
$gif->setImageFormat('gif');
$gif->compositeImage($img, imagick::COMPOSITE_OVER, $x, $y);
$gif->setImageDelay($img->getImageDelay());
$gif->setImageIterations($img->getImageIterations());
} while ($img->nextImage());
$img1->optimizeImageLayers();
$result = $img1->writeImages($path, true);
$img->setFirstIterator();
$img1->newImage($width, $height, new ImagickPixel($bgcolor));
$img1->setImageColorspace($img->getImageColorspace());
$img1->compositeImage($img, imagick::COMPOSITE_OVER, $x, $y);
$result = $this->imagickImage($img1, $path, $destformat, $jpgQuality);
return $result ? $path : false;
extract($this->imageMagickConvertPrepare($path, $destformat, $jpgQuality, $s));
* @var string $deconstruct
* @var string $jpgQuality
* @var string $quotedPath
* @var string $quotedDstPath
if ($bgcolor === 'transparent') {
$bgcolor = 'rgba(255, 255, 255, 0.0)';
$cmd = sprintf('%s -size %dx%d "xc:%s" png:- | convert%s%s%s png:- %s -geometry +%d+%d -compose over -composite%s %s', ELFINDER_CONVERT_PATH, $width, $height, $bgcolor, $coalesce, $jpgQuality, $interlace, $quotedPath, $x, $y, $deconstruct, $quotedDstPath);
if ($this->procExec($cmd) === 0) {
return $result ? $path : false;
elFinder::expandMemoryForGD(array($s, array($width, $height)));
$img = $this->gdImageCreate($path, $s['mime']);
if ($img && false != ($tmp = imagecreatetruecolor($width, $height))) {
$this->gdImageBackground($tmp, $bgcolor);
if ($bgcolor === 'transparent' && ($destformat === 'png' || $s[2] === IMAGETYPE_PNG)) {
$bgNum = imagecolorallocatealpha($tmp, 255, 255, 255, 127);
imagefill($tmp, 0, 0, $bgNum);
if (!imagecopy($tmp, $img, $x, $y, 0, 0, $s[0], $s[1])) {
$result = $this->gdImage($tmp, $path, $destformat, $s['mime'], $jpgQuality);
return $result ? $path : false;
* @param string $path image file
* @param int $degree rotete degrees
* @param string $bgcolor square background color in #rrggbb format
* @param string $destformat image destination format
* @param int $jpgQuality JEPG quality (1-100)
* @throws elFinderAbortException
protected function imgRotate($path, $degree, $bgcolor = '#ffffff', $destformat = null, $jpgQuality = null)
if (($s = getimagesize($path)) == false || $degree % 360 === 0) {
if ($degree % 90 === 0 && in_array($s[2], array(IMAGETYPE_JPEG, IMAGETYPE_JPEG2000))) {
$count = ($degree / 90) % 4;
$quotedPath = escapeshellarg($path);
if ($this->procExec(ELFINDER_EXIFTRAN_PATH . ' -h') === 0) {
$cmds[] = ELFINDER_EXIFTRAN_PATH . ' -i ' . $exiftran[$count] . ' -- ' . $quotedPath;
if ($this->procExec(ELFINDER_JPEGTRAN_PATH . ' -version') === 0) {
$cmds[] = ELFINDER_JPEGTRAN_PATH . ' -rotate ' . $jpegtran[$count] . ' -copy all -outfile ' . $quotedPath . ' -- ' . $quotedPath;
foreach ($cmds as $cmd) {
if ($this->procExec($cmd) === 0) {
$jpgQuality = $this->options['jpgQuality'];
elFinder::extendTimeLimit(300);
$img = new imagick($path);
if ($s[2] === IMAGETYPE_GIF || $s[2] === IMAGETYPE_PNG) {
$bgcolor = 'rgba(255, 255, 255, 0.0)';
if ($img->getNumberImages() > 1) {
$img = $img->coalesceImages();
$img->rotateImage(new ImagickPixel($bgcolor), $degree);
} while ($img->nextImage());
$img->optimizeImageLayers();
$result = $img->writeImages($path, true);
$img->rotateImage(new ImagickPixel($bgcolor), $degree);
$result = $this->imagickImage($img, $path, $destformat, $jpgQuality);
return $result ? $path : false;
extract($this->imageMagickConvertPrepare($path, $destformat, $jpgQuality, $s));
* @var string $deconstruct
* @var string $jpgQuality
* @var string $quotedPath
* @var string $quotedDstPath
if ($s[2] === IMAGETYPE_GIF || $s[2] === IMAGETYPE_PNG) {
$bgcolor = 'rgba(255, 255, 255, 0.0)';
$cmd = sprintf('%s%s%s%s -background "%s" -rotate %d%s -- %s %s', ELFINDER_CONVERT_PATH, $coalesce, $jpgQuality, $interlace, $bgcolor, $degree, $deconstruct, $quotedPath, $quotedDstPath);
if ($this->procExec($cmd) === 0) {
return $result ? $path : false;
elFinder::expandMemoryForGD(array($s, $s));
$img = $this->gdImageCreate($path, $s['mime']);
if ($s[2] === IMAGETYPE_GIF) {
$bgIdx = imagecolortransparent($img);
$c = imagecolorsforindex($img, $bgIdx);
$newImg = imagecreatetruecolor($w, $h);
imagepalettecopy($newImg, $img);
$bgNum = imagecolorallocate($newImg, $c['red'], $c['green'], $c['blue']);
imagefill($newImg, 0, 0, $bgNum);
imagecolortransparent($newImg, $bgNum);
imagecopy($newImg, $img, 0, 0, 0, 0, $w, $h);
} else if ($s[2] === IMAGETYPE_PNG) {
$bgNum = imagecolorallocatealpha($img, 255, 255, 255, 127);
list($r, $g, $b) = sscanf($bgcolor, "#%02x%02x%02x");
$bgNum = imagecolorallocate($img, $r, $g, $b);
$tmp = imageRotate($img, $degree, $bgNum);
imagecolortransparent($tmp, $bgNum);
$result = $this->gdImage($tmp, $path, $destformat, $s['mime'], $jpgQuality);
return $result ? $path : false;
* @param string $command command line
* @param string $output stdout strings
* @param int $return_var process exit code
* @param string $error_output stderr strings
* @throws elFinderAbortException
* @author Alexey Sukhotin
protected function procExec($command, &$output = '', &$return_var = -1, &$error_output = '', $cwd = null)
return elFinder::procExec($command, $output, $return_var, $error_output);
* Remove thumbnail, also remove recursively if stat is directory
* @param array $stat file stat
* @throws elFinderAbortException
* @author Dmitry (dio) Levashov
protected function rmTmb($stat)
if ($this->tmbPathWritable) {
if ($stat['mime'] === 'directory') {
foreach ($this->scandirCE($this->decode($stat['hash'])) as $p) {
elFinder::extendTimeLimit(30);
$name = $this->basenameCE($p);
$name != '.' && $name != '..' && $this->rmTmb($this->stat($p));
} else if (!empty($stat['tmb']) && $stat['tmb'] != "1") {
$tmb = $this->tmbPath . DIRECTORY_SEPARATOR . rawurldecode($stat['tmb']);
file_exists($tmb) && unlink($tmb);
* Create an gd image according to the specified mime type
* @param string $path image file
* @return resource|false GD image resource identifier
protected function gdImageCreate($path, $mime)
return imagecreatefromjpeg($path);
return imagecreatefrompng($path);
return imagecreatefromgif($path);
if (!function_exists('imagecreatefrombmp')) {
include_once dirname(__FILE__) . '/libs/GdBmp.php';
return imagecreatefrombmp($path);
return imagecreatefromxbm($path);
return imagecreatefromxpm($path);
return imagecreatefromwebp($path);
* Output gd image to file
* @param resource $image gd image resource
* @param string $filename The path to save the file to.
* @param string $destformat The Image type to use for $filename
* @param string $mime The original image mime type
* @param int $jpgQuality JEPG quality (1-100)
protected function gdImage($image, $filename, $destformat, $mime, $jpgQuality = null)
$jpgQuality = $this->options['jpgQuality'];