@@ -509,7 +509,6 @@ def _get_image(
509
509
try :
510
510
if isinstance (id , str ) and id .find (RES .PATTERN ) == 0 :
511
511
pattern_name = id [len (RES .PATTERN ) : id .find ("/" , len (RES .PATTERN ) + 1 )]
512
- image_name = id [id .rfind ("/" ) :]
513
512
514
513
patterns = cast (
515
514
DictionaryObject ,
@@ -538,26 +537,24 @@ def _get_image(
538
537
if self .inline_images is None : # pragma: no cover
539
538
raise KeyError ("no inline image can be found" )
540
539
return self .inline_images [id ]
541
- elif id .find ("/Pattern" ) == 0 :
542
- imgd = _xobj_to_image (cast (DictionaryObject , xobjs [image_name ]))
543
- extension , byte_stream = imgd [:2 ]
544
- f = ImageFile (
545
- name = f"{ pattern_name [1 :]} _{ image_name [1 :]} { extension } " ,
546
- data = byte_stream ,
547
- image = imgd [2 ],
548
- indirect_reference = xobjs [image_name ].indirect_reference ,
549
- )
550
- return f
540
+
541
+ if id .find ("/Pattern" ) == 0 :
542
+ image_identifier = id [id .rfind ("/" ) :]
543
+
544
+ image_name = pattern_name [1 :] + "_" + image_identifier [1 :]
551
545
else :
552
- imgd = _xobj_to_image (cast (DictionaryObject , xobjs [id ]))
553
- extension , byte_stream = imgd [:2 ]
554
- f = ImageFile (
555
- name = f"{ id [1 :]} { extension } " ,
556
- data = byte_stream ,
557
- image = imgd [2 ],
558
- indirect_reference = xobjs [id ].indirect_reference ,
559
- )
560
- return f
546
+ image_identifier = str (id )
547
+ image_name = id [1 :]
548
+
549
+ imgd = _xobj_to_image (cast (DictionaryObject , xobjs [image_identifier ]))
550
+ image_extension , byte_stream = imgd [:2 ]
551
+
552
+ return ImageFile (
553
+ name = image_name + str (image_extension ),
554
+ data = byte_stream ,
555
+ image = imgd [2 ],
556
+ indirect_reference = xobjs [image_identifier ].indirect_reference ,
557
+ )
561
558
else : # in a sub object
562
559
ids = id [1 :]
563
560
return self ._get_image (ids , cast (DictionaryObject , xobjs [id [0 ]]))
0 commit comments