psliwa / PHPPdf

Pdf and graphic files generator library written in php
http://ohey.pl
MIT License
339 stars 77 forks source link

Divide by zero #112

Open ambroisemaupate opened 8 years ago

ambroisemaupate commented 8 years ago

A divide by zero is occuring in Util.php on line 59 in calculateDependantSizes method.

When ratio is not set or null or 0.

Could we throw an exception when this method parameters does not match requirements?

Moreover $ratio can be zero in ImageConvertAttributesFormatter line 40 $originalRatio = $originalHeight ? $originalWidth/$originalHeight : 0;

millejano commented 7 years ago

There is also a "Division by zero" Warning if using a combination of keep-ration and ignore-error for a non existing image.

An example: styles.xml `

`

image.pdf.twig `

`

The images doesn't exists.

Warning Message: Division by zero see psliwa/php-pdf/lib/PHPPdf/Core/Node/Image.php at line 97 $sourceRatio = $sourceImage->getOriginalHeight() / $sourceImage->getOriginalWidth();

Quickfix for line 94 before: if($keepRatio after: if($keepRatio && $sourceImage->getOriginalWidth())

Can you fix this booth issues in a new version, pls.