def cvtStandardImgFormat(self, savePath, fmt, compression=False): im_arr = self.getPixelArray() if fmt.endswith('jpg') and im_arr[0] > 65535 and im_arr[1] > 65535: print('Too Large size for JPEG-2000 format...') return elif fmt.endswith('png') and im_arr[0] > 10000 and im_arr[1] > 10000: print('Too Large size for PNG format...') return fname = os.path.basename(self.filename) sname = os.path.splitext(fname)[-1] im = Image.new_from_array(im_arr) if fmt.endswith('tiff'): if compression: im.write_to_file(savePath + '/' + sname + '.' + fmt, compression='lzw') else: im.write_to_file(savePath + '/' + sname + '.' + fmt, compression='lzw') else: im.write_to_file(savePath + '/' + sname + '.' + fmt)
def test_vips_to_numpy(): img = VIPSImage.new_from_array([[1, 2, 3], [4, 5, 6]]) arr = vips_to_numpy(img) h, w, d = arr.shape assert w == img.width assert h == img.height assert d == img.bands assert arr.dtype == vips_format_to_dtype[img.format]