Skip to content

Commit

Permalink
MDL-50041 gdlib: Badges need PNG files from process_new_icon()
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederic Massart committed Apr 29, 2015
1 parent 84ea226 commit cda2a82
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/badgeslib.php
Expand Up @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions lib/gdlib.php
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions lib/upgrade.txt
Expand Up @@ -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 ===

Expand Down

0 comments on commit cda2a82

Please sign in to comment.