Forum


Replies: 3   Views: 757
Devision by zero in line 51
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by CarlEOgden  · 13-10-2020 - 07:13

Hi

I couldn't find any other posts stating this error, but when we try to create a docx, sometimes an image makes an exception:-

```
 

array:1 [
  "e" => Exception {#2290
    #message: "Division by zero"
    #code: 0
    #file: "/mnt/storage/standout/public_html/dev/public/phpdocx/classes/PhpdocxLogger.php"
    #line: 51
    trace: {
      /mnt/storage/standout/public_html/dev/public/phpdocx/classes/PhpdocxLogger.php:51 {
        PhpdocxLogger::logger($message, $level) …
        › if ($level == 'fatal') {    throw new Exception($message);}
      }

```

But all the values in the image are greater than zero, in fact they are ["Width"]=> int(2048) ["Height"]=> int(1366) and we  force the image width to be 295.

The code is:

```
$image_options = [
'height' => ($room_photograph->Height / $room_photograph->Width) * $image_width,
'src' => $room_photograph->MediaURL,
'imageAlign' => 'center',
'textWrap' => 0,
'width' => $image_width,
];

```

Any ideas on how to fix this issue?

Thanks in advance
Carl.

Posted by admin  · 13-10-2020 - 08:39

Hello,

The only case where phpdocx could return that exception when adding an image is if the image doesn't have a dpi or it's set as 0, but it should return the following exception: There was an error adding the image. In this case you can set a custom dpi using the dpi option.

If you send to contact[at]phpdocx.com an image that illustrates your issue, we'll check it.

Regards.

Posted by CarlEOgden  · 13-10-2020 - 11:52

Hi

Thanks for your reply, using Preview of the image, the DPI is 96.

Kind regards
Carl.

Posted by CarlEOgden  · 13-10-2020 - 11:58

Hi

I've added 'dpi' => 96, when creating the image and this has now resolved the issue and my routine is working without crashing.

Thank you for your help
Carl.