Output as image in format determined by filename extension. Args: output: (str) only use to overrule filename extension. Default is PNG. Others are JPEG, JPG, PNM, PGM, PPM, PBM, PAM, PSD, PS.
(self, filename, output=None, jpg_quality=95)
| 13833 | return mupdf.fz_pixmap_samples_int(self.this) |
| 13834 | |
| 13835 | def save(self, filename, output=None, jpg_quality=95): |
| 13836 | """Output as image in format determined by filename extension. |
| 13837 | |
| 13838 | Args: |
| 13839 | output: (str) only use to overrule filename extension. Default is PNG. |
| 13840 | Others are JPEG, JPG, PNM, PGM, PPM, PBM, PAM, PSD, PS. |
| 13841 | """ |
| 13842 | valid_formats = { |
| 13843 | "png": 1, |
| 13844 | "pnm": 2, |
| 13845 | "pgm": 2, |
| 13846 | "ppm": 2, |
| 13847 | "pbm": 2, |
| 13848 | "pam": 3, |
| 13849 | "psd": 5, |
| 13850 | "ps": 6, |
| 13851 | "jpg": 7, |
| 13852 | "jpeg": 7, |
| 13853 | } |
| 13854 | |
| 13855 | if type(filename) is str: |
| 13856 | pass |
| 13857 | elif hasattr(filename, "absolute"): |
| 13858 | filename = str(filename) |
| 13859 | elif hasattr(filename, "name"): |
| 13860 | filename = filename.name |
| 13861 | if output is None: |
| 13862 | _, ext = os.path.splitext(filename) |
| 13863 | output = ext[1:] |
| 13864 | |
| 13865 | idx = valid_formats.get(output.lower(), None) |
| 13866 | if idx is None: |
| 13867 | raise ValueError(f"Image format {output} not in {tuple(valid_formats.keys())}") |
| 13868 | if self.alpha and idx in (2, 6, 7): |
| 13869 | raise ValueError(f"'{output}' cannot have alpha") |
| 13870 | if self.colorspace and self.colorspace.n > 3 and idx in (1, 2, 4): |
| 13871 | raise ValueError(f"unsupported colorspace for '{output}'") |
| 13872 | if idx == 7: |
| 13873 | self.set_dpi(self.xres, self.yres) |
| 13874 | return self._writeIMG(filename, idx, jpg_quality) |
| 13875 | |
| 13876 | def set_alpha(self, alphavalues=None, premultiply=1, opaque=None, matte=None): |
| 13877 | """Set alpha channel to values contained in a byte array. |