From cda2a8273a9012822ee22c7c591e2e1db66378a2 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Wed, 29 Apr 2015 15:04:47 +0800 Subject: [PATCH] MDL-50041 gdlib: Badges need PNG files from process_new_icon() --- lib/badgeslib.php | 2 +- lib/gdlib.php | 10 +++++++--- lib/upgrade.txt | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/badgeslib.php b/lib/badgeslib.php index 622d7f0c6e5..c8af3f8a6c9 100644 --- a/lib/badgeslib.php +++ b/lib/badgeslib.php @@ -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. diff --git a/lib/gdlib.php b/lib/gdlib.php index f9ac929c325..948d783ed1f 100644 --- a/lib/gdlib.php +++ b/lib/gdlib.php @@ -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. diff --git a/lib/upgrade.txt b/lib/upgrade.txt index bc4d1e555ee..d603042badc 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -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 ===