From 593540cc19b2e2a51e2d025b1904edd37e9fa43b Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Mon, 22 Feb 2021 18:13:12 +0100 Subject: [PATCH] MDL-70968 core: PHP8 compatibility, not allowed to pass extra parameters --- lib/gdlib.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/gdlib.php b/lib/gdlib.php index 72fdb4141d9..c384d79f2aa 100644 --- a/lib/gdlib.php +++ b/lib/gdlib.php @@ -233,6 +233,14 @@ function process_new_icon($context, $component, $filearea, $itemid, $originalfil $icon = array('contextid'=>$context->id, 'component'=>$component, 'filearea'=>$filearea, 'itemid'=>$itemid, 'filepath'=>'/'); + if ($imagefnc === 'imagejpeg') { + // Function imagejpeg() accepts less arguments than imagepng() but we need to make $imagefnc accept the same + // number of arguments, otherwise PHP8 throws an error. + $imagefnc = function($image, $filename, $quality, $unused) { + return imagejpeg($image, $filename, $quality); + }; + } + ob_start(); if (!$imagefnc($im1, NULL, $quality, $filters)) { // keep old icons @@ -384,6 +392,14 @@ function resize_image_from_image($original, $imageinfo, $width, $height, $forcec imagecopybicubic($newimage, $original, $dstx, $dsty, 0, 0, $targetwidth, $targetheight, $originalwidth, $originalheight); + if ($imagefnc === 'imagejpeg') { + // Function imagejpeg() accepts less arguments than imagepng() but we need to make $imagefnc accept the same + // number of arguments, otherwise PHP8 throws an error. + $imagefnc = function($image, $filename, $quality, $unused) { + return imagejpeg($image, $filename, $quality); + }; + } + // Capture the image as a string object, rather than straight to file. ob_start(); if (!$imagefnc($newimage, null, $quality, $filters)) { -- 2.11.4.GIT