PJLink
PJLink copied to clipboard
Error when using topil()
I was trying the tutorial in the following link. When I tried to load the image using topil() function, it resulted in the error - "ValueError: Size must be a tuple". I think this is because res1.dimensions is of type <class 'numpy.ndarray'>
and Image.py expects it to be list or tuple. Please find below the traceback and the code.
with MathematicaBlock():
res1 = MEval(
Rasterize(
Plot(Sin (M.x), List (M.x, 0, Times (2, Pi)),
ImageSize = [250, 250],
PlotLabel = "sin(x) as plotted in Mathematica"
)
)
)
print(isinstance(res1.dimensions, (list, tuple)))
res1.topil()
Output:
False
ValueError Traceback (most recent call last)
~/Library/Mathematica/Paclets/Repository/PJLink-1.0.6/PJLink/HelperClasses.py in topil(self) 128 129 def topil(self): --> 130 print("changes") 131 return self._topil(self.dimensions, self.color_space, self.image_type, self.data, self.channels) 132
~/Library/Mathematica/Paclets/Repository/PJLink-1.0.6/PJLink/HelperClasses.py in _topil(cls, dims, cs, itype, data, channels) 89 dbuf = cast.data 90 ---> 91 return Image.frombuffer(mode, tuple(dims), dbuf, "raw", mode, 0, 1) 92 93 @property
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/PIL/Image.py in frombuffer(mode, size, data, decoder_name, *args) 2410 """ 2411 -> 2412 _check_size(size) 2413 2414 # may pass tuple instead of argument list
/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/PIL/Image.py in _check_size(size) 2292 2293 if not isinstance(size, (list, tuple)): -> 2294 raise ValueError("Size must be a tuple") 2295 if len(size) != 2: 2296 raise ValueError("Size must be a tuple of length 2")
ValueError: Size must be a tuple
Thanks for the detailed report. I'll try to get to it when I can. Meantime try this: https://github.com/WolframResearch/WolframClientForPython