diff --git a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php index 9ea6b2e..5fe5de5 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php +++ b/core/modules/system/src/Plugin/ImageToolkit/GDToolkit.php @@ -480,7 +480,9 @@ protected static function supportedTypes() { * @param int $height * The image height. * @param int $bits_per_pixel - * (optional) The bits per pixel of the image. Defaults to 32 (4 bytes). + * (optional) The bits per pixel of the image. Defaults to 31, as GD + * internally manages RGB with 8 bits each color + 7 bits for the alpha + * channel. * @param float $tweak_factor * (optional) A tweak factor as described in * http://php.net/manual/en/function.imagecreatetruecolor.php#99623. @@ -492,8 +494,11 @@ protected static function supportedTypes() { * * @see http://php.net/manual/en/function.imagecreatetruecolor.php#99623 */ - public function checkAvailableMemory($width, $height, $bits_per_pixel = 32, $tweak_factor = 1.7) { - $required = (int) ($width * $height * ($bits_per_pixel / 8) * $tweak_factor); + public function checkAvailableMemory($width, $height, $bits_per_pixel = 31, $tweak_factor = 1.7) { + // Bytes per pixel need to accommodate enough bytes to store all the bits + // needed. + $bytes_per_pixel = ceil($bits_per_pixel / 8); + $required = (int) ($width * $height * $bytes_per_pixel * $tweak_factor); $memory = new EnvironmentMemory(); if ($memory->checkAvailable($required)) { $this->memoryInfo = [];