Python: Problem mit .jpeg?

1 Antwort

Mit deinem Posting kann man wenig anfangen.

Offenbar ist self.horz_dpi gerade 0 und durch 0 darf man bekanntlich nicht teilen.

Ist die Python-Datei [bla bla]e-packages\docx\image\image.py von dir geschrieben?

Da du den interessanten Teil weggelöscht hast, kann man nicht sagen, wo die Funktion width aufgerufen wurde, in der durch 0 geteilt wird.

Woher ich das weiß:Berufserfahrung

HagbardCeline88 
Fragesteller
 19.02.2023, 16:30
Traceback (most recent call last):
  File "C:\Users\NUTZER\Desktop\NBASE\rembot.py", line 455, in <module>
    main()
  File "C:\Users\NUTZER\Desktop\NBASE\rembot.py", line 452, in main
    main_()
  File "C:\Users\NUTZER\Desktop\NBASE\rembot.py", line 404, in main_
    Table.cell(0, 1).paragraphs[0].runs[0].add_picture(REM[1],width=Cm(4.5))
  File "C:\Users\NUTZER\AppData\Local\Programs\Python\Python310\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:\Users\NUTZER\AppData\Local\Programs\Python\Python310\lib\site-packages\docx\parts\story.py", line 57, in new_pic_inline
    cx, cy = image.scaled_dimensions(width, height)
  File "C:\Users\NUTZER\AppData\Local\Programs\Python\Python310\lib\site-packages\docx\image\image.py", line 158, in scaled_dimensions
    scaling_factor = float(width) / float(self.width)
  File "C:\Users\NUTZER\AppData\Local\Programs\Python\Python310\lib\site-packages\docx\image\image.py", line 126, in width
    return Inches(self.px_width / self.horz_dpi)
ZeroDivisionError: division by zero
0
HagbardCeline88 
Fragesteller
 19.02.2023, 16:33
@HagbardCeline88

in einem teil der jpeg sind einfach wichtige infos nicht vorhanden. die bilder sind aber net von mir, ka wie ich das lösen soll. btw: auf dieser plattform gibts ne zeichenbegrenzung..,..

0
HagbardCeline88 
Fragesteller
 19.02.2023, 19:42
@GuteAntwort2021

Hm wofür _genau_ kann ich nicht sagen leider. Aber das ich eigentlich n Noob bin schon :D . Naja hatte es aber gelöst, indem ich einfach Glück beim googeln hatte; wäre ich alleine net drauf gekommen:

from docx.image.image import Image
from docx.shared import Inches

@property
def image_width(self):
    if (self.horz_dpi == 0):
        return Inches(self.px_width / 72)
    return Inches(self.px_width / self.horz_dpi)


@property
def image_height(self):
    if (self.vert_dpi == 0):
        return Inches(self.px_height / 72)
    return Inches(self.px_height / self.vert_dpi)


Image.width = image_width
Image.height = image_height

und das ganze hab ich dann wohl zufällig an die richtige stelle kopiert :D oh man.. ich bin echt n noob haha

0