Skip to content

Commit 9c1e92e

Browse files
Progi1984jaapdh
andauthored
Gd::setImageResource() : Fixed when imagecreatetruecolor returns false (#843)
* SetImageResource receives the output from imagecreatetruecolor which can also be false or GdImage * fix linter error * `Gd::setImageResource()` : Fixed when imagecreatetruecolor returns false * Fixed PHPCSFixer * Fixed changelog --------- Co-authored-by: Jaap den Hollander <[email protected]>
1 parent c7dd41c commit 9c1e92e

File tree

4 files changed

+9
-2
lines changed

4 files changed

+9
-2
lines changed

docs/changes/1.2.0.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
- CI : Fixed PHPCSFixer by [@kw-pr](https://github.com/kw-pr) in [#835](https://github.com/PHPOffice/PHPPresentation/pull/835)
1616
- Word2007 Reader: Fixed cast of color by [@Progi1984](https://github.com/Progi1984) fixing [#826](https://github.com/PHPOffice/PHPPresentation/pull/826) in [#840](https://github.com/PHPOffice/PHPPresentation/pull/840)
1717
- Word2007 Reader: Fixed panose with 20 characters by [@Progi1984](https://github.com/Progi1984) fixing [#798](https://github.com/PHPOffice/PHPPresentation/pull/798) in [#842](https://github.com/PHPOffice/PHPPresentation/pull/842)
18+
- `Gd::setImageResource()` : Fixed when imagecreatetruecolor returns false by [@jaapdh](https://github.com/jaapdh) in [#843](https://github.com/PHPOffice/PHPPresentation/pull/843)
1819

1920
## Miscellaneous
2021

phpstan.neon.dist

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ parameters:
1616
- '#^Parameter \#1 \$pValue of static method PhpOffice\\Common\\Drawing\:\:pixelsToCentimeters\(\) expects int, float given\.#'
1717
- '#^Parameter \#1 \$pValue of static method PhpOffice\\Common\\Drawing\:\:pixelsToEmu\(\) expects int, float given\.#'
1818
## PHP 8.0 & GdImage
19+
- '#^Parameter \$value of method PhpOffice\\PhpPresentation\\Shape\\Drawing\\Gd::setImageResource\(\) has invalid type GdImage.#'
1920
- '#^Parameter \#1 \$value of method PhpOffice\\PhpPresentation\\Shape\\Drawing\\Gd::setImageResource\(\) expects resource\|null, GdImage\ given\.#'
2021
- '#^Parameter \#1 \$value of method PhpOffice\\PhpPresentation\\Shape\\Drawing\\Gd::setImageResource\(\) expects resource\|null, GdImage\|false given\.#'
2122
- '#^Parameter \#1 \$value of method PhpOffice\\PhpPresentation\\Shape\\Drawing\\Gd::setImageResource\(\) expects resource\|null, \(GdImage\|false\) given\.#'

src/PhpPresentation/Reader/PowerPoint2007.php

+3
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,9 @@ protected function loadShapeDrawing(XMLReader $document, DOMElement $node, Abstr
829829
if (!empty($imageFile)) {
830830
if ($oShape instanceof Gd) {
831831
$info = getimagesizefromstring($imageFile);
832+
if (!$info) {
833+
return;
834+
}
832835
$oShape->setMimeType($info['mime']);
833836
$oShape->setRenderingFunction(str_replace('/', '', $info['mime']));
834837
$image = @imagecreatefromstring($imageFile);

src/PhpPresentation/Shape/Drawing/Gd.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
namespace PhpOffice\PhpPresentation\Shape\Drawing;
2222

23+
use GdImage;
24+
2325
class Gd extends AbstractDrawingAdapter
2426
{
2527
// Rendering functions
@@ -84,15 +86,15 @@ public function getImageResource()
8486
/**
8587
* Set image resource.
8688
*
87-
* @param resource $value
89+
* @param null|false|GdImage|resource $value
8890
*
8991
* @return $this
9092
*/
9193
public function setImageResource($value = null)
9294
{
9395
$this->imageResource = $value;
9496

95-
if (null !== $this->imageResource) {
97+
if (null !== $this->imageResource && false !== $this->imageResource) {
9698
// Get width/height
9799
$this->width = imagesx($this->imageResource);
98100
$this->height = imagesy($this->imageResource);

0 commit comments

Comments
 (0)