I want to know the size of the image, the solution is the following, using pgmagick I open the images and save it into an array:

img = Image('image_1.jpeg') 

and using numpy find out the size

 width=np.size(img,0) height = np.size(img,1) 

As a result, I see the following error:

Traceback (most recent call last): File "/home/alex/PycharmProjects/untitled/create_file_annotation.py", line 56, in width = np.size (img, 0) File "/usr/lib/python2.7/dist -packages / numpy / core / fromnumeric.py ", line 2702, in size return asarray (a) .shape [axis] IndexError: tuple index out of range

And the most interesting thing is that I set print weight,height and the image size is correct before an error, what could be the cause of the error? Python using version 2.7

    1 answer 1

    This error occurs when np.size() takes a array_like - array_like object as the first argument, for example:

     In [58]: np.size(111, 0) ... skipped ... IndexError: tuple index out of range 

    img is an object of the pgmagic.Image class.

    Solution :

     width, height = img.width, img.height 
    • And what are these attributes, width and height? Where do you need to take them? - engineer_7
    • @ Alexey Anikeev, did you open the link ? - MaxU
    • one
      I am sorry for not attentiveness! Thanks a lot, it all worked. - engineer_7