Skip to content
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

createDrawingShape stopped working in 1.1.0 #820

Open
sinnbeck opened this issue Sep 6, 2024 · 4 comments · May be fixed by #833
Open

createDrawingShape stopped working in 1.1.0 #820

sinnbeck opened this issue Sep 6, 2024 · 4 comments · May be fixed by #833

Comments

@sinnbeck
Copy link

sinnbeck commented Sep 6, 2024

I am adding images to a powerpoint and it was working fine in v1.0.

This is the code

foreach ($images as $imagePath) {
    $slide = $presentation->createSlide();
    $shape = $slide->createDrawingShape();
    $shape->setPath($imagePath);
    $shape->setResizeProportional(true);
    $shape->setWidth($width);
    $shape->setOffsetX(0);
    $shape->setOffsetY(0);
    $shape->setName('Content');
    $shape->setDescription('Content');
}

Now after updating I just get an empty page with "Content"
image

It works if I use this, but I want to add them as drawing shapes

$image = new Image();
$image->setPath($imagePath);
$slide->setBackground($image);
@omarjavierr277
Copy link

I am adding images to a powerpoint and it was working fine in v1.0.

Captura de pantalla 2024-09-25 a la(s) 4 33 47 p  m

code

$imageFile = new File();
$imageFile->setPath($filePath)->setName(time());
$this->activeSlide->addShape($imageFile);

@eandradesimbi
Copy link

I'm having the same issue… has anyone found a solution?

@andy96453
Copy link

Same problem, I am creating a powerpoint file with an image on each slide all was working corectly, when upgraded to 1.1 only a few slides had images the rest were broken when writing out to PowerPoint2007

@kw-pr
Copy link
Contributor

kw-pr commented Nov 26, 2024

Quick fix: Change name or description for each image ->setDescription('lorum ipsum' . random_int(0, 99999))

What I got so far
The following are my notes during the search:

Same here. Drawing works the first time but if used again the image does not show.

I checked src/PhpPresentation/Shape/Drawing/File.php but is does not have any big changes. Problem is somewhere else...

Unpacking the .pptx files: the slides and rels files look fine.
But the images are missing in ppt/media/.

In PptMedia the images are missing from getDrawingHashTable().

They disappear in src/PhpPresentation/Writer/PowerPoint2007.php Line 98:

$this->getDrawingHashTable()->addFromSource($this->allDrawings());

Looks like getHashCode() is the same for my images.
There is AbstractGraphic::getHashCode() and AbstractShape::getHashCode() involved. Second one was changed, but I don't see any problem. Same problem with the old AbstractShape::getHashCode() function.

AbstractGraphic looks like this:

public function getHashCode(): string
{
    return md5($this->name . $this->description . parent::getHashCode() . __CLASS__);
}

If you change name or description of the image the hash changes all images show up.

Only a hack. Not a real solution, yet.

In v1.0.0 $this->container->getHashCode() is always different!

In v1.1.0 container is empty in AbstractShape.

addShape function was removed in many places:

src/PhpPresentation/Slide/AbstractSlide.php
src/PhpPresentation/Slide/Animation.php
src/PhpPresentation/Slide/Note.php
src/PhpPresentation/Shape/Group.php

But it is still in the interface and I think it is used. Should throw an exception?

Ah, addShape that is in PhpOffice\PhpPresentation\Traits\ShapeCollection now. But there is no $shape->setContainer($this); anymore.

kw-pr added a commit to kw-pr/PHPPresentation that referenced this issue Nov 27, 2024
Added setContainer in ShapeCollection::addShape().
kw-pr added a commit to kw-pr/PHPPresentation that referenced this issue Nov 27, 2024
@kw-pr kw-pr linked a pull request Dec 12, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment