Update unit test and changelog

This commit is contained in:
Ivan Lanin 2014-04-13 18:03:59 +07:00
parent abc67edb50
commit e78489b36e
3 changed files with 9 additions and 7 deletions

View File

@ -31,6 +31,7 @@ This release marked heavy refactorings on internal code structure with the creat
- Endnote: Ability to add endnotes - @ivanlanin
- ListItem: Ability to create custom list and reset list number - @ivanlanin GH-10 GH-198
- ODT Writer: Basic table writing support - @ivanlanin
- Image: Keep image aspect ratio if only 1 dimension styled - @japonicus GH-194
### Bugfixes

View File

@ -133,14 +133,15 @@ class Image extends AbstractElement
$this->style = $this->setStyle(new ImageStyle(), $style, true);
$styleWidth = $this->style->getWidth();
$styleHeight = $this->style->getHeight();
list($actualWidth, $actualHeight) = $imgData;
if (!($styleWidth && $styleHeight)) {
if ($styleWidth == null && $styleHeight == null) {
$this->style->setWidth($imgData[0]);
$this->style->setHeight($imgData[1]);
} else if ($styleWidth) {
$this->style->setHeight($imgData[1] * ($styleWidth / $imgData[0]));
$this->style->setWidth($actualWidth);
$this->style->setHeight($actualHeight);
} elseif ($styleWidth) {
$this->style->setHeight($actualHeight * ($styleWidth / $actualWidth));
} else {
$this->style->setWidth($imgData[0] * ($styleHeight / $imgData[1]));
$this->style->setWidth($actualWidth * ($styleHeight / $actualHeight));
}
}
$this->setImageFunctions();

View File

@ -129,7 +129,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
public function testPNG()
{
$src = __DIR__ . "/../_files/images/firefox.png";
$oImage = new Image($src);
$oImage = new Image($src, array('width' => 100));
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage);
$this->assertEquals($oImage->getSource(), $src);
@ -146,7 +146,7 @@ class ImageTest extends \PHPUnit_Framework_TestCase
public function testGIF()
{
$src = __DIR__ . "/../_files/images/mario.gif";
$oImage = new Image($src);
$oImage = new Image($src, array('height' => 100));
$this->assertInstanceOf('PhpOffice\\PhpWord\\Element\\Image', $oImage);
$this->assertEquals($oImage->getSource(), $src);