diff --git a/inc/document.class.php b/inc/document.class.php index e5ed027db4d..83edf2b54d4 100644 --- a/inc/document.class.php +++ b/inc/document.class.php @@ -1623,12 +1623,14 @@ public static function getImage($path, $context, $mwidth = null, $mheight = null } $infos = pathinfo($path); + // output images with possible transparency to png, other to jpg + $extension = in_array(strtolower($infos['extension']), ['png', 'gif']) ? 'png' : 'jpg'; $context_path = sprintf( '%1$s_%2$s-%3$s.%4$s', $infos['dirname'] . '/' . $infos['filename'], $mwidth, $mheight, - 'jpg' //resizePicture always produces JPG files + $extension ); //let's check if file already exists diff --git a/inc/toolbox.class.php b/inc/toolbox.class.php index 0f126167236..3b06c289dac 100644 --- a/inc/toolbox.class.php +++ b/inc/toolbox.class.php @@ -1351,12 +1351,31 @@ static function resizePicture($source_path, $dest_path, $new_width = 71, $new_he //create new img resource for store thumbnail $source_dest = imagecreatetruecolor($new_width, $new_height); + // set transparent background for PNG/GIF + if ($img_type === IMAGETYPE_GIF || $img_type === IMAGETYPE_PNG) { + imagecolortransparent($source_dest, imagecolorallocatealpha($source_dest, 0, 0, 0, 127)); + imagealphablending($source_dest, false); + imagesavealpha($source_dest, true); + } + //resize image imagecopyresampled($source_dest, $source_res, 0, 0, $img_x, $img_y, $new_width, $new_height, $img_width, $img_height); //output img - return imagejpeg($source_dest, $dest_path, 90); + $result = null; + switch ($img_type) { + case IMAGETYPE_GIF : + case IMAGETYPE_PNG : + $result = imagepng($source_dest, $dest_path); + break; + + case IMAGETYPE_JPEG : + default : + $result = imagejpeg($source_dest, $dest_path, 90); + break; + } + return $result; } diff --git a/inc/user.class.php b/inc/user.class.php index 56b1cdd509e..2df8cdd9104 100755 --- a/inc/user.class.php +++ b/inc/user.class.php @@ -711,8 +711,13 @@ function prepareInputForUpdate($input) { // Move uploaded file $filename = uniqid($this->fields['id'].'_'); $sub = substr($filename, -2); /* 2 hex digit */ - $tmp = explode(".", $input["_picture"]); - $extension = Toolbox::strtolower(array_pop($tmp)); + + // output images with possible transparency to png, other to jpg + $extension = strtolower(pathinfo($fullpath, PATHINFO_EXTENSION)); + $extension = in_array($extension, ['png', 'gif']) + ? 'png' + : 'jpg'; + @mkdir(GLPI_PICTURE_DIR . "/$sub"); $picture_path = GLPI_PICTURE_DIR . "/$sub/${filename}.$extension"; self::dropPictureFiles("$sub/${filename}.$extension");