diff --git a/administrator/components/com_templates/models/template.php b/administrator/components/com_templates/models/template.php index 2d2ae86fb849f..fce6481c69978 100644 --- a/administrator/components/com_templates/models/template.php +++ b/administrator/components/com_templates/models/template.php @@ -1159,12 +1159,26 @@ public function cropImage($file, $w, $h, $x, $y) $client = JApplicationHelper::getClientInfo($template->client_id); $relPath = base64_decode($file); $path = JPath::clean($client->path . '/templates/' . $template->element . '/' . $relPath); - $JImage = new JImage($path); try { - $image = $JImage->crop($w, $h, $x, $y, true); - $image->toFile($path); + $image = new \JImage($path); + $properties = $image->getImageFileProperties($path); + + switch ($properties->mime) + { + case 'image/png': + $imageType = \IMAGETYPE_PNG; + break; + case 'image/gif': + $imageType = \IMAGETYPE_GIF; + break; + default: + $imageType = \IMAGETYPE_JPEG; + } + + $image->crop($w, $h, $x, $y, false); + $image->toFile($path, $imageType); return true; } @@ -1195,12 +1209,25 @@ public function resizeImage($file, $width, $height) $relPath = base64_decode($file); $path = JPath::clean($client->path . '/templates/' . $template->element . '/' . $relPath); - $JImage = new JImage($path); - try { - $image = $JImage->resize($width, $height, true, 1); - $image->toFile($path); + $image = new \JImage($path); + $properties = $image->getImageFileProperties($path); + + switch ($properties->mime) + { + case 'image/png': + $imageType = \IMAGETYPE_PNG; + break; + case 'image/gif': + $imageType = \IMAGETYPE_GIF; + break; + default: + $imageType = \IMAGETYPE_JPEG; + } + + $image->resize($width, $height, false, \JImage::SCALE_FILL); + $image->toFile($path, $imageType); return true; }