Transform Node to a QImage processes the image, names it based on metadata, and saves the image to the disk.
(self, dirname="")
| 283 | self.node.setName(newName) |
| 284 | |
| 285 | def save(self, dirname=""): |
| 286 | """ |
| 287 | Transform Node to a QImage |
| 288 | processes the image, names it based on metadata, and saves the image to the disk. |
| 289 | """ |
| 290 | img = nodeToImage(self) |
| 291 | meta = self.cfg["meta"].copy() |
| 292 | |
| 293 | if self.inherit: |
| 294 | meta.update(self.inheritedMetadata()) |
| 295 | |
| 296 | meta.update(self.meta) |
| 297 | |
| 298 | margin, scale = meta["m"], meta["s"] |
| 299 | extension, path = meta["e"], meta["p"][0] |
| 300 | bilinear = meta["b"][0].lower() not in ["no", "false"] |
| 301 | |
| 302 | dirPath = ( |
| 303 | exportPath(self.cfg, path, dirname, userDefined=True) |
| 304 | if path |
| 305 | else exportPath(self.cfg, pathFS(self.parent), dirname, userDefined=False) |
| 306 | ) |
| 307 | dirPath.mkdir(parents=True, exist_ok=True) |
| 308 | |
| 309 | def appendName(path, name, scale, margin, extension): |
| 310 | """ |
| 311 | Appends a formatted name to the path argument |
| 312 | Returns the full path with the file |
| 313 | """ |
| 314 | meta_s = self.cfg["meta"]["s"][0] |
| 315 | out = name |
| 316 | out += "_@{}x".format(scale / 100) if scale != meta_s else "" |
| 317 | out += "_m{:03d}".format(margin) if margin else "" |
| 318 | out += "." + extension |
| 319 | out = path / out |
| 320 | return out.as_posix() |
| 321 | |
| 322 | it = product(scale, margin, extension) |
| 323 | # Below: scale for scale, margin for margin, extension for extension |
| 324 | it = starmap( |
| 325 | lambda scale, margin, extension: ( |
| 326 | scale, |
| 327 | margin, |
| 328 | extension, |
| 329 | appendName(dirPath, self.name, scale, margin, extension), |
| 330 | ), |
| 331 | it, |
| 332 | ) |
| 333 | it = starmap( |
| 334 | lambda scale, margin, extension, path: ( |
| 335 | [int(1e-2 * wh * scale) for wh in self.size], |
| 336 | 100 - scale != 0, |
| 337 | Qt.TransformationMode.SmoothTransformation if bilinear else Qt.TransformationMode.FastTransformation, |
| 338 | margin, |
| 339 | extension, |
| 340 | path, |
| 341 | ), |
| 342 | it, |