diff --git a/src/PIL/IcoImagePlugin.py b/src/PIL/IcoImagePlugin.py index 5de561782..ca47e14d6 100644 --- a/src/PIL/IcoImagePlugin.py +++ b/src/PIL/IcoImagePlugin.py @@ -121,14 +121,12 @@ def _accept(prefix): class IcoFile: def __init__(self, buf): """ - Parse image from file-like object containing ico file data + Parse image from file-like object containing ico/cur file data """ # check magic s = buf.read(6) - if not _accept(s): - msg = "not an ICO file" - raise SyntaxError(msg) + self._check_header(s) self.buf = buf self.entry = [] @@ -182,6 +180,11 @@ class IcoFile: self.entry = sorted(self.entry, key=lambda x: x["square"]) self.entry.reverse() + def _check_header(self, header): + if not _accept(header): + msg = "not an ICO file" + raise SyntaxError(msg) + def sizes(self): """ Get a list of all available icon sizes and color depths. @@ -308,8 +311,11 @@ class IcoImageFile(ImageFile.ImageFile): format = "ICO" format_description = "Windows Icon" + # For subclasses. + _ico_file_class = IcoFile + def _open(self): - self.ico = IcoFile(self.fp) + self.ico = self._ico_file_class(self.fp) self.info["sizes"] = self.ico.sizes() self.size = self.ico.entry[0]["dim"] self.load()