Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using topil() #7

Open
gaganso opened this issue Dec 3, 2018 · 1 comment
Open

Error when using topil() #7

gaganso opened this issue Dec 3, 2018 · 1 comment

Comments

@gaganso
Copy link

gaganso commented Dec 3, 2018

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)
in ()
9 )
10 print(isinstance(res1.dimensions, (list, tuple)))
---> 11 res1.topil()

~/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

@b3m2a1
Copy link
Owner

b3m2a1 commented Jan 8, 2019

Thanks for the detailed report. I'll try to get to it when I can. Meantime try this: https://github.com/WolframResearch/WolframClientForPython

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants