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

DivisionByZero when inserting images #356

Closed
spinto opened this Issue May 31, 2016 · 3 comments

Comments

2 participants
@spinto

spinto commented May 31, 2016

Hi,
in case of some JPG images where DPI is set to 0, the insert_image will fail at workbook closure with a DivisionByZero error.

I was able to fix this by changing the condition of the "# Workaround for incorrect dpi." in the _process_jpg function of the workbook.py file from == 1 to <= 1. With this patch, excel seems to load the image correctly (assuiming DPIs equal to 96)

@jmcnamara jmcnamara self-assigned this May 31, 2016

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara May 31, 2016

Owner

Hi Salvatore,

Thanks for the report, I'll fix it soon.

Could you attach a sample image with 0 dpi (if it isn't confidential) and I'll create a test case around it. If not I'll generate one myself.

John

Owner

jmcnamara commented May 31, 2016

Hi Salvatore,

Thanks for the report, I'll fix it soon.

Could you attach a sample image with 0 dpi (if it isn't confidential) and I'll create a test case around it. If not I'll generate one myself.

John

@spinto

This comment has been minimized.

Show comment
Hide comment
@spinto

spinto May 31, 2016

You can find the test image here: test

And the code which will trigger the division by zero is:

import xlsxwriter

workbook = xlsxwriter.Workbook('test.xlsx')
worksheet = workbook.add_worksheet('test')
worksheet.write(0,0,'test')
worksheet.insert_image(0,1, 'test.jpg', {'x_scale': 3, 'y_scale': 3})

workbook.close()

Cheers,
Salvatore.

spinto commented May 31, 2016

You can find the test image here: test

And the code which will trigger the division by zero is:

import xlsxwriter

workbook = xlsxwriter.Workbook('test.xlsx')
worksheet = workbook.add_worksheet('test')
worksheet.write(0,0,'test')
worksheet.insert_image(0,1, 'test.jpg', {'x_scale': 3, 'y_scale': 3})

workbook.close()

Cheers,
Salvatore.

jmcnamara added a commit that referenced this issue May 31, 2016

@jmcnamara

This comment has been minimized.

Show comment
Hide comment
@jmcnamara

jmcnamara May 31, 2016

Owner

Fixed in release 0.8.9: http://xlsxwriter.readthedocs.io/changes.html

Thanks for the report.

John

Owner

jmcnamara commented May 31, 2016

Fixed in release 0.8.9: http://xlsxwriter.readthedocs.io/changes.html

Thanks for the report.

John

@jmcnamara jmcnamara closed this May 31, 2016

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