@@ -76,10 +76,15 @@ class LocalBackend(ABC):
76
76
@classmethod
77
77
@abstractmethod
78
78
def version (cls ) -> Any :
79
+ """Return the backend version if its dependencies are satisfied or
80
+ raise `LocalBackendNotAvailableError`.
81
+ """
79
82
pass
80
83
81
84
@classmethod
82
85
def available (cls ) -> bool :
86
+ """Return `True` this backend's dependencies are satisfied and it can
87
+ be used, `False` otherwise."""
83
88
try :
84
89
cls .version ()
85
90
return True
@@ -95,10 +100,15 @@ def resize(
95
100
quality : int = 0 ,
96
101
max_filesize : int = 0 ,
97
102
) -> bytes :
103
+ """Resize an image to the given width and return the output path.
104
+
105
+ On error, logs a warning and returns `path_in`.
106
+ """
98
107
pass
99
108
100
109
@abstractmethod
101
110
def get_size (self , path_in : bytes ) -> tuple [int , int ] | None :
111
+ """Return the (width, height) of the image or None if unavailable."""
102
112
pass
103
113
104
114
@abstractmethod
@@ -107,10 +117,15 @@ def deinterlace(
107
117
path_in : bytes ,
108
118
path_out : bytes | None = None ,
109
119
) -> bytes :
120
+ """Remove interlacing from an image and return the output path.
121
+
122
+ On error, logs a warning and returns `path_in`.
123
+ """
110
124
pass
111
125
112
126
@abstractmethod
113
127
def get_format (self , path_in : bytes ) -> str | None :
128
+ """Return the image format (e.g., 'PNG') or None if undetectable."""
114
129
pass
115
130
116
131
@abstractmethod
@@ -120,10 +135,15 @@ def convert_format(
120
135
target : bytes ,
121
136
deinterlaced : bool ,
122
137
) -> bytes :
138
+ """Convert an image to a new format and return the new file path.
139
+
140
+ On error, logs a warning and returns `source`.
141
+ """
123
142
pass
124
143
125
144
@property
126
145
def can_compare (self ) -> bool :
146
+ """Indicate whether image comparison is supported by this backend."""
127
147
return False
128
148
129
149
def compare (
@@ -132,14 +152,24 @@ def compare(
132
152
im2 : bytes ,
133
153
compare_threshold : float ,
134
154
) -> bool | None :
155
+ """Compare two images and return `True` if they are similar enough, or
156
+ `None` if there is an error.
157
+
158
+ This must only be called if `self.can_compare()` returns `True`.
159
+ """
135
160
# It is an error to call this when ArtResizer.can_compare is not True.
136
161
raise NotImplementedError ()
137
162
138
163
@property
139
164
def can_write_metadata (self ) -> bool :
165
+ """Indicate whether writing metadata to images is supported."""
140
166
return False
141
167
142
168
def write_metadata (self , file : bytes , metadata : Mapping [str , str ]) -> None :
169
+ """Write key-value metadata into the image file.
170
+
171
+ This must only be called if `self.can_write_metadata()` returns `True`.
172
+ """
143
173
# It is an error to call this when ArtResizer.can_write_metadata is not True.
144
174
raise NotImplementedError ()
145
175
0 commit comments