# Print Array of image in terminal

**URL:** <https://discourse.processing.org/t/print-array-of-image-in-terminal/23090>\
**Category:** Processing.py\
**Created:** [August 6, 2020, 6:43pm UTC](https://discourse.processing.org/t/print-array-of-image-in-terminal/23090 "2020-08-06T18:43:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![juanjoc](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@juanjoc](https://discourse.processing.org/u/juanjoc)\
**Post date:** [August 6, 2020, 6:43pm UTC](https://discourse.processing.org/t/print-array-of-image-in-terminal/23090/1 "2020-08-06T18:43:26Z")

</div>

Hello everyone. I’m interested in printing the array data of an image in terminal. For example in python I load the image, then I only use print(image) to see the array list of the picture. In processing this is not as trivial as I thought.

Here is my code

```auto
def setup():
    size(500,500)
    global img
    img = loadImage("Image.png")
    loadPixels()
    printArray(img)
    
def draw():
    background(255)
    image(img,0,0)

```

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 6, 2020, 7:13pm UTC](https://discourse.processing.org/t/print-array-of-image-in-terminal/23090/2 "2020-08-06T19:13:30Z")

</div>

> [@juanjoc](#):
>
> I’m interested in printing the array data of an image in terminal.

> **[pixels \\ Language (API)](https://py.processing.org/reference/pixels.html)**
>
> Python Mode for Processing extends the Processing Development Environment with the Python programming language.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [August 6, 2020, 7:13pm UTC](https://discourse.processing.org/t/print-array-of-image-in-terminal/23090/3 "2020-08-06T19:13:55Z")

</div>

> [@juanjoc](#):
>
> In processing this is not as trivial as I thought.

In Processing (Java):

```auto
PImage myImage;

void setup() 
  {
  size(100, 100);
  myImage = loadImage("apples.png");
  myImage.loadPixels();
  printArray(myImage.pixels);
  }

void draw() 
  {
  image(myImage, 0, 0);
  }

```

Started here and modified:

> **[loadPixels() / Reference](https://processing.org/reference/loadPixels_.html)**
>
> Loads the pixel data of the current display window into the pixels\[\] array. This function must always be called before reading from or writing to pixels\[\]. Subsequent changes to the disp…

I see category changed to Python now…

`:)`

---

<div class="post-metadata">

**Author:** ![juanjoc](https://avatars.discourse-cdn.com/v4/letter/j/e480ec/32.png) [@juanjoc](https://discourse.processing.org/u/juanjoc)\
**Post date:** [August 6, 2020, 9:41pm UTC](https://discourse.processing.org/t/print-array-of-image-in-terminal/23090/4 "2020-08-06T21:41:07Z")

</div>

Ok, now I write the example but the value is not an RGB color.

```auto
def setup():
    size(11,11)
    global img
    img = loadImage("prueba.png")
    image(img,0,0)
    loadPixels()
    print(pixels)
    
def draw():
    background(255)
    image(img,0,0)

```

It is worth pointing that the size of the image is (10x5)px and it returns the following

 ![Capture](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/bd7a8dae853e415632e70f867023d9479f113f2c.png)

Then I realized in the description of pixels feature that I need to write

```auto
color b = pixels[index]

```

But it returns me an error of compilation

```auto
def setup():
    size(11,11)
    global img
    img = loadImage("prueba.png")
    image(img,0,0)
    loadPixels()
    color b = pixels[1]
    print(b)
    
def draw():
    background(255)
    image(img,0,0)

```

> Maybe there’s an unclosed paren or quote mark somewere before this line?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [August 6, 2020, 9:49pm UTC](https://discourse.processing.org/t/print-array-of-image-in-terminal/23090/5 "2020-08-06T21:49:26Z")

</div>

> [@juanjoc](#):
>
> `color b = pixels[1]`

We don’t declare a variable’s datatype on Python 2! So it’s just: `b = pixels[1]`
