Skip to content

Commit

Permalink
MDL-46763 core: Change icon processing to retain source format
Browse files Browse the repository at this point in the history
  • Loading branch information
gthomas2 authored and stronk7 committed Feb 10, 2015
1 parent 3b77006 commit 78c36b0
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions lib/gdlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ function process_new_icon($context, $component, $filearea, $itemid, $originalfil
}

$imageinfo = getimagesize($originalfile);
$imagefnc = '';

if (empty($imageinfo)) {
return false;
Expand Down Expand Up @@ -137,6 +138,13 @@ function process_new_icon($context, $component, $filearea, $itemid, $originalfil
debugging('JPEG not supported on this server');
return false;
}
// If the user uploads a jpeg them we should process as a jpeg if possible.
if (function_exists('imagejpeg')) {
$imagefnc = 'imagejpeg';
$imageext = '.jpg';
$filters = null; // Not used.
$quality = 90;
}
break;
case IMAGETYPE_PNG:
if (function_exists('imagecreatefrompng')) {
Expand All @@ -150,19 +158,22 @@ function process_new_icon($context, $component, $filearea, $itemid, $originalfil
return false;
}

if (function_exists('imagepng')) {
$imagefnc = 'imagepng';
$imageext = '.png';
$filters = PNG_NO_FILTER;
$quality = 1;
} else if (function_exists('imagejpeg')) {
$imagefnc = 'imagejpeg';
$imageext = '.jpg';
$filters = null; // not used
$quality = 90;
} else {
debugging('Jpeg and png not supported on this server, please fix server configuration');
return false;
// The conversion has not been decided yet, let's apply defaults (png with fallback to jpg).
if (empty($imagefnc)) {
if (function_exists('imagepng')) {
$imagefnc = 'imagepng';
$imageext = '.png';
$filters = PNG_NO_FILTER;
$quality = 1;
} else if (function_exists('imagejpeg')) {
$imagefnc = 'imagejpeg';
$imageext = '.jpg';
$filters = null; // Not used.
$quality = 90;
} else {
debugging('Jpeg and png not supported on this server, please fix server configuration');
return false;
}
}

if (function_exists('imagecreatetruecolor')) {
Expand Down

0 comments on commit 78c36b0

Please sign in to comment.