-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Image src as base64 is not working #1246
Comments
can you give a code sample that reproduces the issue? |
I had to change my approach since using base64 as an image source was not resource friendly. Though there seems to be a problem when img tag is not closed. Is there a fix for this instead or do I have to manually close the img tag which would be tricky for my part since the content is PHP generated. |
@rebbieboi right now, as we are loading XML and not HTML, the tag needs to be closed as otherwise it is not valid XML. |
@troosan Thank you for that information. :) Last question if you don't mind. How can I set default dimensions for the content generated from an HTML source? Images tend to take a full 100% width meaning it won't sometimes fit. |
when you addHTML, you add it to a container. I guess if you set a fixed with to that container the content should not be wider than that. |
@rebbieboi Have you been able to fix it? I have the same problem with img base64: "Invalid image: data:image/png;base64,iVBORw0..." |
Hi, I have the same issue. If I try to load HTML directly to phpWord, img is not correctly used and I have nothing in my document. I solve this in 3 places : \Element\Image.php \Writer\AbstractWriter.php The must would be to remove the base64 part when it's decoded from HTML. Can you help me to put it in the right place ? |
I've find better : No need to update Image.php & AbstractWriter.php private static function parseImage($node, $element)
{
$style = array();
$src = null;
foreach ($node->attributes as $attribute) {
switch ($attribute->name) {
case 'src':
$src = $attribute->value;
if(preg_match('/^(.*base64,)/m', $src)) {
$src = base64_decode(preg_replace('/^(.*base64,)/m', '', $src));
}
break; |
This is:
Expected Behavior
Should display the image
Current Behavior
Image is not displayed
Failure Information
I get this errors instead:
Uncaught PhpOffice\PhpWord\Exception\InvalidImageException: Invalid image: data:image/jpeg;base64,/9j/4AAQSkZJRgABAgEAYABgAAD/7gAOQWRv.....
Please help provide information about the failure.
How to Reproduce
I am using a base64 image
Context
The text was updated successfully, but these errors were encountered: