Skip to content

Commit

Permalink
Gd::setImageResource() : Fixed when imagecreatetruecolor returns fa…
Browse files Browse the repository at this point in the history
…lse (#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 <jaapdh@yahoo.com>
  • Loading branch information
Progi1984 and jaapdh authored Jan 17, 2025
1 parent c7dd41c commit 9c1e92e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changes/1.2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- CI : Fixed PHPCSFixer by [@kw-pr](https://github.com/kw-pr) in [#835](https://github.com/PHPOffice/PHPPresentation/pull/835)
- 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)
- 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)
- `Gd::setImageResource()` : Fixed when imagecreatetruecolor returns false by [@jaapdh](https://github.com/jaapdh) in [#843](https://github.com/PHPOffice/PHPPresentation/pull/843)

## Miscellaneous

Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ parameters:
- '#^Parameter \#1 \$pValue of static method PhpOffice\\Common\\Drawing\:\:pixelsToCentimeters\(\) expects int, float given\.#'
- '#^Parameter \#1 \$pValue of static method PhpOffice\\Common\\Drawing\:\:pixelsToEmu\(\) expects int, float given\.#'
## PHP 8.0 & GdImage
- '#^Parameter \$value of method PhpOffice\\PhpPresentation\\Shape\\Drawing\\Gd::setImageResource\(\) has invalid type GdImage.#'
- '#^Parameter \#1 \$value of method PhpOffice\\PhpPresentation\\Shape\\Drawing\\Gd::setImageResource\(\) expects resource\|null, GdImage\ given\.#'
- '#^Parameter \#1 \$value of method PhpOffice\\PhpPresentation\\Shape\\Drawing\\Gd::setImageResource\(\) expects resource\|null, GdImage\|false given\.#'
- '#^Parameter \#1 \$value of method PhpOffice\\PhpPresentation\\Shape\\Drawing\\Gd::setImageResource\(\) expects resource\|null, \(GdImage\|false\) given\.#'
Expand Down
3 changes: 3 additions & 0 deletions src/PhpPresentation/Reader/PowerPoint2007.php
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,9 @@ protected function loadShapeDrawing(XMLReader $document, DOMElement $node, Abstr
if (!empty($imageFile)) {
if ($oShape instanceof Gd) {
$info = getimagesizefromstring($imageFile);
if (!$info) {
return;
}
$oShape->setMimeType($info['mime']);
$oShape->setRenderingFunction(str_replace('/', '', $info['mime']));
$image = @imagecreatefromstring($imageFile);
Expand Down
6 changes: 4 additions & 2 deletions src/PhpPresentation/Shape/Drawing/Gd.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

namespace PhpOffice\PhpPresentation\Shape\Drawing;

use GdImage;

class Gd extends AbstractDrawingAdapter
{
// Rendering functions
Expand Down Expand Up @@ -84,15 +86,15 @@ public function getImageResource()
/**
* Set image resource.
*
* @param resource $value
* @param null|false|GdImage|resource $value
*
* @return $this
*/
public function setImageResource($value = null)
{
$this->imageResource = $value;

if (null !== $this->imageResource) {
if (null !== $this->imageResource && false !== $this->imageResource) {
// Get width/height
$this->width = imagesx($this->imageResource);
$this->height = imagesy($this->imageResource);
Expand Down

0 comments on commit 9c1e92e

Please sign in to comment.