From ac5dd15e16580b08752aaa2a816d6d550aca7940 Mon Sep 17 00:00:00 2001 From: Adrien CLERC Date: Fri, 15 Feb 2019 22:08:14 +0100 Subject: [PATCH] create static method to transform a Jpeg into an Mpo This is dirty "downcasting". It just works in this special case. --- src/PIL/MpoImagePlugin.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/PIL/MpoImagePlugin.py b/src/PIL/MpoImagePlugin.py index 0a267117e..216ed9fbc 100644 --- a/src/PIL/MpoImagePlugin.py +++ b/src/PIL/MpoImagePlugin.py @@ -98,6 +98,22 @@ class MpoImageFile(JpegImagePlugin.JpegImageFile): finally: self.__fp = None + @staticmethod + def adopt(jpeg_instance, mpheader=None): + ''' + Transform the instance of JpegImageFile into + instance of MpoImageFile. + After the call, the JpegImageFile is extended + to be an MpoImageFile. + + This is essentially useful when opening a JPEG + file that reveals itself as an MPO, to avoid + double call to _open. + ''' + jpeg_instance.__class__ = MpoImageFile + jpeg_instance._after_jpeg_open(mpheader) + return jpeg_instance + # --------------------------------------------------------------------- # Registry stuff