PHPPresentation icon indicating copy to clipboard operation
PHPPresentation copied to clipboard

Error when adding images other than jpeg

Open Bagasdew opened this issue 6 years ago • 6 comments

So I've tried to add images using Base64 with jpeg file types and it works fine. But when I use png or svg+xml type it return this error: image Did the library is not yet supporting images other than jpeg? thanks a lot

Bagasdew avatar Jun 19 '19 13:06 Bagasdew

@Bagasdew Hi, Thank you for your issue. Could you check the develop branch ?

Progi1984 avatar Oct 19 '19 14:10 Progi1984

PNG support appears to have been added on the develop branch, but not SVG. I tried adding 'image/svg+xml' => 'svg', to https://github.com/PHPOffice/PHPPresentation/blob/develop/src/PhpPresentation/Shape/Drawing/Base64.php#L25 and it doesn't throw the exception, but I get this when loading the generated pptx in PowerPoint:

image

chriswheeler avatar Mar 19 '20 15:03 chriswheeler

Any change of svg support being added as PowerPoint supports embedding SVG files?

joelg99 avatar Jun 17 '20 04:06 joelg99

@chriswheeler @Bagasdew @joelg99 Hi, Could you send me a PowerPoint file with a SVG image, for analysis, please ?

Progi1984 avatar Aug 21 '24 22:08 Progi1984

@Progi1984 - I have just emailed over an example. It actually works for the fist image embed with PNG or SVG but breaks for subsequent embeds.

image

chriswheeler avatar Nov 19 '24 17:11 chriswheeler

Sorry, I've been working on this a bit more, and realised the root of the problem is that I was using the same 'Name' for each image.

$shape->setName('Image')

If I changed my code to give a unique name for each image, e.g.

$shape->setName('Image'.md5($svg))

It now works as expected.

Perhaps it would be worth throwing an exception or logging an error if the same name is reused and they need to be unique.

chriswheeler avatar Nov 19 '24 17:11 chriswheeler