From 8cab7037af0ee8e500efc93057c67d33ebddda91 Mon Sep 17 00:00:00 2001 From: Stephanie Wagner Date: Sat, 20 Apr 2013 10:15:31 -0400 Subject: [PATCH 1/2] Fixed "undefined function imagepng" error by checking if GD is enabled before saving pngs. --- Classes/PHPExcel/Writer/Excel5.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Classes/PHPExcel/Writer/Excel5.php b/Classes/PHPExcel/Writer/Excel5.php index 37f5b85c3..30e7a90d8 100644 --- a/Classes/PHPExcel/Writer/Excel5.php +++ b/Classes/PHPExcel/Writer/Excel5.php @@ -481,7 +481,10 @@ private function _buildWorkbookEscher() case 1: // GIF, not supported by BIFF8, we convert to PNG $blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG; ob_start(); - imagepng(imagecreatefromgif($filename)); + if(extension_loaded('gd') && function_exists('gd_info')) + { + imagepng(imagecreatefromgif($filename)); + } $blipData = ob_get_contents(); ob_end_clean(); break; @@ -499,7 +502,10 @@ private function _buildWorkbookEscher() case 6: // Windows DIB (BMP), we convert to PNG $blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG; ob_start(); + if(extension_loaded('gd') && function_exists('gd_info')) + { imagepng(PHPExcel_Shared_Drawing::imagecreatefrombmp($filename)); + } $blipData = ob_get_contents(); ob_end_clean(); break; From d0eccd4531493e6627089303f96ccfe1c7163554 Mon Sep 17 00:00:00 2001 From: Stephanie Date: Mon, 29 Apr 2013 19:49:15 -0400 Subject: [PATCH 2/2] throws exception if gd is not enabled when creating a png file. --- Classes/PHPExcel/Writer/Excel5.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/Classes/PHPExcel/Writer/Excel5.php b/Classes/PHPExcel/Writer/Excel5.php index 30e7a90d8..285bdda49 100644 --- a/Classes/PHPExcel/Writer/Excel5.php +++ b/Classes/PHPExcel/Writer/Excel5.php @@ -481,10 +481,15 @@ private function _buildWorkbookEscher() case 1: // GIF, not supported by BIFF8, we convert to PNG $blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG; ob_start(); - if(extension_loaded('gd') && function_exists('gd_info')) + if(extension_loaded('gd')) { imagepng(imagecreatefromgif($filename)); } + else + { + + throw new PHPExcel_Writer_Exception("Failed to create PNG file -- GD is not enabled."); + } $blipData = ob_get_contents(); ob_end_clean(); break; @@ -502,9 +507,13 @@ private function _buildWorkbookEscher() case 6: // Windows DIB (BMP), we convert to PNG $blipType = PHPExcel_Shared_Escher_DggContainer_BstoreContainer_BSE::BLIPTYPE_PNG; ob_start(); - if(extension_loaded('gd') && function_exists('gd_info')) + if(extension_loaded('gd')) + { + imagepng(PHPExcel_Shared_Drawing::imagecreatefrombmp($filename)); + } + else { - imagepng(PHPExcel_Shared_Drawing::imagecreatefrombmp($filename)); + throw new PHPExcel_Writer_Exception("Failed to create PNG file -- GD is not enabled."); } $blipData = ob_get_contents(); ob_end_clean();