-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
add_picture #187
Comments
I think there are issues with some JPEG-EXIF images, one was reported recently. Does it work with some JPEGs and not others? There are some test images you can try here: |
it looks like the error is only present on images from IOS, i saw the thread on the differences in the exif data, but is there a way to modify the exif so that it reads correctly? or are there any plans to update the code to read the ios 8.3 images. |
I'm open to a patch if someone wants to dig in there and see what it would take. Unfortunately I'm tied up with other projects now and don't plan to be in there for a while. |
The image parser of docx doesn't work with some exif data python-openxml/python-docx#187 We have already all needed data in the image part, thus we don't need to parse the image data
I have met the same error, is it considered to be fixed? |
I've having the same issue with a .JPG file. I'm on latest version 0.8.10. Has there been a fix? |
Same error here. Is there a fix? |
For those who are still looking for solution - use Fotosizer Standard Edition. there is option under Miscellaneous Settings -> Image Metadata and Dates -> uncheck all boxes and save/convert images. You don't need to resize. There is option for orginal size on top. For me that fixed docx.image.exceptions.UnexpectedEndOfFileError |
Also, if you're on linux, you can try to convert jpg to png using imagemagik's convert command |
python-docx can't parse some jpeg files correctly, so we use PIL to format all jpeg files to workaround this issue when generate docx file.
python-docx can't parse some jpeg files correctly, so we use PIL to format all jpeg files to workaround this issue when generating docx file.
Workaround python-docx bug python-openxml/python-docx#187
在百度贴吧找到了问题原因和解决方法: 原贴地址:https://tieba.baidu.com/p/6409886653?red_tag=1219468420 |
Oh my god... |
Almost 6 years later, I am getting the same error message BTW, I am using images produced by a scanner attached to another Win7 32bit PC. |
This 9 years old issue is now fixed in #1451 ! |
I am new to python and I am having issues witth add_picture
my code is simple
from docx import Document
from docx.shared import Inches
document = Document()
document.add_heading('Document Title', 0)
document.add_picture('IMG_2063.jpg')
document.add_page_break()
document.save('demo.docx')
for some reason it was working and now i get a long string of errors. i cant seem to see what i am doing wrong. if nothting do i need to reinstall?
here is the error
E:\calculations\temp>doc2.py
Traceback (most recent call last):
File "E:\calculations\temp\doc2.py", line 18, in
document.add_picture('IMG_2063.jpg')
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\document.py", line 79, in add_picture
return run.add_picture(image_path_or_stream, width, height)
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\text\run.py", line 62, in add_picture
inline = self.part.new_pic_inline(image_path_or_stream, width, height)
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\parts\document.py", line 91, in new_pic_inline
rId, image = self.get_or_add_image(image_descriptor)
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\parts\document.py", line 54, in get_or_add_image
image_descriptor
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\package.py", line 76, in get_or_add_image_part
image = Image.from_file(image_descriptor)
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\image.py", line 55, in from_file
return cls._from_stream(stream, blob, filename)
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\image.py", line 176, in _from_stream
image_header = _ImageHeaderFactory(stream)
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\image.py", line 198, in _ImageHeaderFactory
return cls.from_stream(stream)
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\jpeg.py", line 47, in from_stream
markers = _JfifMarkers.from_stream(stream)
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\jpeg.py", line 111, in from_stream
for marker in marker_parser.iter_markers():
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\jpeg.py", line 177, in iter_markers
marker_code, self._stream, segment_offset
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\jpeg.py", line 271, in _MarkerFactory
return marker_cls.from_stream(stream, marker_code, offset)
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\jpeg.py", line 413, in from_stream
tiff = cls._tiff_from_exif_segment(stream, offset, segment_length)
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\jpeg.py", line 455, in _tiff_from_exif_segment
return Tiff.from_stream(substream)
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\tiff.py", line 36, in from_stream
parser = _TiffParser.parse(stream)
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\tiff.py", line 63, in parse
ifd_entries = _IfdEntries.from_stream(stream_rdr, ifd0_offset)
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\tiff.py", line 176, in from_stream
entries = dict((e.tag, e.value) for e in ifd_parser.iter_entries())
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\tiff.py", line 176, in
entries = dict((e.tag, e.value) for e in ifd_parser.iter_entries())
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\tiff.py", line 204, in iter_entries
ifd_entry = _IfdEntryFactory(self._stream_rdr, dir_entry_offset)
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\tiff.py", line 231, in _IfdEntryFactory
return entry_cls.from_stream(stream_rdr, offset)
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\tiff.py", line 256, in from_stream
stream_rdr, offset, value_count, value_offset
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\tiff.py", line 294, in _parse_value
return stream_rdr.read_str(value_count-1, value_offset)
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\helpers.py", line 70, in read_str
chars = self._unpack_item(struct, base, offset)
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\helpers.py", line 96, in unpack_item
bytes = self._read_bytes(struct.size, base, offset)
File "C:\Python27\ArcGISx6410.2\lib\site-packages\docx\image\helpers.py", line 88, in _read_bytes
raise UnexpectedEndOfFileError
docx.image.exceptions.UnexpectedEndOfFileError
The text was updated successfully, but these errors were encountered: