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

image width not set #1254

Closed
nicdnepr opened this issue Jan 22, 2018 · 7 comments
Closed

image width not set #1254

nicdnepr opened this issue Jan 22, 2018 · 7 comments
Milestone

Comments

@nicdnepr
Copy link

nicdnepr commented Jan 22, 2018

This is:

a bug report

Expected Behavior

docx with table, one column with image with fixed width

Current Behavior

image with full size

Failure Information

How to Reproduce

Please provide a code sample that reproduces the issue.

<?php
require __DIR__ . '/vendor/autoload.php';

$phpWord = new PhpWord();
        $section = $phpWord->addSection();
        \PhpOffice\PhpWord\Shared\Html::addHtml($section, '<table style="width:100%"><tr><td><img src="https://www.gettyimages.ca/gi-resources/images/Homepage/Hero/UK/CMS_Creative_164657191_Kingfisher.jpg" style="width: 20px;"/></td><td>text</td></tr></table>');

        $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
        $objWriter->save($docx);

Context

  • PHP version: 7
  • PHPWord version: 0.14
@sergeizelenyi
Copy link
Contributor

maybe you can help set:

src/PhpWord/Style/Image.php
$this->setUnit(self::UNIT_PX) instead of $this->setUnit(self::UNIT_PT);

in the previous release there was : px
in 0.14 it could be a mistake: pt

P.S. translate.google :(

@troosan
Copy link
Contributor

troosan commented Feb 2, 2018

Indeed, this is due to the fix for #224
To fix this, try to change PhpWord/Shared/Html::parseImage and add the following in the case for width and height

    $style['unit'] = \PhpOffice\PhpWord\Style\Image::UNIT_PX;

Please tell me if that fixes the issue.

@sergeizelenyi
Copy link
Contributor

Please tell me if that fixes the issue.

resolve in my case

@troosan troosan added this to the v0.15.0 milestone Feb 6, 2018
@troosan
Copy link
Contributor

troosan commented Feb 6, 2018

@sergeizelenyi great, I'll include a fix in the next release

@troosan troosan mentioned this issue Feb 6, 2018
2 tasks
troosan added a commit that referenced this issue Feb 9, 2018
@troosan troosan closed this as completed Feb 10, 2018
@simogeo
Copy link

simogeo commented Sep 10, 2019

It seems i still have a similar issue using phpWord v0.16

Please see : https://stackoverflow.com/questions/57867641/controling-image-size-with-addhtml-from-phpword-0-16-library

Any idea ?

@simogeo
Copy link

simogeo commented Sep 22, 2019

Please, any clue regarding this ?

@simogeo
Copy link

simogeo commented Sep 28, 2019

I expected php-word to interpret width value from style attribute. It seems, it is not the default behavior.

Actually, to solve my issue, I just remove my style attribute dynamically and add a width attribute to img tag using SimpleHTMLDOM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants