MDL-50041 gdlib: Badges need PNG files from process_new_icon()

This commit is contained in:
Frederic Massart 2015-04-29 15:04:47 +08:00
parent 84ea226616
commit cda2a8273a
3 changed files with 10 additions and 4 deletions

View File

@ -966,7 +966,7 @@ function badges_process_badge_image(badge $badge, $iconfile) {
require_once($CFG->libdir. '/gdlib.php');
if (!empty($CFG->gdversion)) {
process_new_icon($badge->get_context(), 'badges', 'badgeimage', $badge->id, $iconfile);
process_new_icon($badge->get_context(), 'badges', 'badgeimage', $badge->id, $iconfile, true);
@unlink($iconfile);
// Clean up file draft area after badge image has been saved.

View File

@ -88,16 +88,20 @@ function imagecopybicubic($dst_img, $src_img, $dst_x, $dst_y, $src_x, $src_y, $d
}
/**
* Stores optimised icon images in icon file area
* Stores optimised icon images in icon file area.
*
* Since 2.9 this function will generate an icon in the same format as the original file when possible.
* To counter that behaviour, you can use the argument $preferpng to generate a PNG icon.
*
* @param context $context
* @param string $component
* @param string filearea
* @param int $itemid
* @param string $originalfile
* @param boolean $preferpng When true, it will try to generate a PNG file regardless of the original file.
* @return mixed new unique revision number or false if not saved
*/
function process_new_icon($context, $component, $filearea, $itemid, $originalfile) {
function process_new_icon($context, $component, $filearea, $itemid, $originalfile, $preferpng = false) {
global $CFG;
if (!is_file($originalfile)) {
@ -139,7 +143,7 @@ function process_new_icon($context, $component, $filearea, $itemid, $originalfil
return false;
}
// If the user uploads a jpeg them we should process as a jpeg if possible.
if (function_exists('imagejpeg')) {
if (!$preferpng && function_exists('imagejpeg')) {
$imagefnc = 'imagejpeg';
$imageext = '.jpg';
$filters = null; // Not used.

View File

@ -39,6 +39,8 @@ information provided here is intended especially for developers.
* The outdated lib/google/Google_Client.php and related files have been completely removed. To use
the new client, read lib/google/readme_moodle.txt, please.
* profile_display_badges() has been deprecated. See MDL-48935 for details.
* process_new_icon() now does not always return a PNG file. When possible, it will try to keep the format of the original file.
Set the new argument $preferpng to true to force PNG. See MDL-46763 and MDL-50041 for details.
=== 2.8 ===