Skip to content

Gd::setImageResource() : Fixed when imagecreatetruecolor returns false #843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading