# Generative collage error

**URL:** <https://discourse.processing.org/t/generative-collage-error/45714>\
**Category:** Coding Questions\
**Created:** [February 6, 2025, 2:59am UTC](https://discourse.processing.org/t/generative-collage-error/45714 "2025-02-06T02:59:08Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbanales](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jbanales](https://discourse.processing.org/u/jbanales)\
**Post date:** [February 6, 2025, 2:59am UTC](https://discourse.processing.org/t/generative-collage-error/45714/1 "2025-02-06T02:59:08Z")

</div>

Hello, when I run this code I get this message. There are only 16 images in the sketch and they are in the data/images folder.

```auto
loading…
32images loaded!
The file data/images/._04.jpg contains bad image data, or may not be an image.
IllegalArgumentException: Width (-1) and height (-1) cannot be <= 0

```

```auto
int amount = int(random(1, 10));

PGraphics[] layers = new PGraphics[amount];
PGraphics[] masks = new PGraphics[amount];

import java.io.File;
String [] imageFileNames;
StringList images;

void setup() {
  size(1200, 900);

  java.io.File folder = new java.io.File(dataPath("images"));
  imageFileNames = folder.list();
  images = new StringList();

  println("loading…");
  // Load the image-files and push thems to imagess-arrayList
  for (int i = 0; i < imageFileNames.length; i++) {
    String filename = imageFileNames[I];
    if (filename.indexOf("Store") == -1) {
      images.push("data/images/"+filename);
    }
  }

  println(images.size() + "images loaded!");

  for (int i = 0; i < layers.length; i++) {
    layers[i] = createGraphics(width, height);
    masks[i] = createGraphics(width, height);
  }
}

PGraphics l, m;
PImage img;
void draw() {

  amount = int(random(3, 30));

  background(0);
  //blendMode(SCREEN);
  for (int i = 0; i < layers.length; i++) {
    l = layers[I];
    img = loadImage(images.get(int(random(images.size()))));
    img.resize(width, 0);
    l.beginDraw();
    l.clear();
    l.push();
    l.image(img, 0, 0);
    l.pop();
    l.endDraw();

    m = masks[I];
    m.beginDraw();
    m.background(#FFFFFF);
    m.noStroke();
    m.fill(0);
    m.beginShape();
    for (int j = 0; j < 12; j++) {
      float x = random(-width, width*2);
      float y = random(-height, height*2);
      m.curveVertex(x, y);
    }
    m.endShape();

    if (random(1) < 0.1) {
      m.circle(random(width), random(height), random(width/2));
    }
    m.endDraw();

    l.mask(m);
    image(l, 0, 0);
  }
  // saveFrame("out/###.png");
}

```

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [February 6, 2025, 8:55am UTC](https://discourse.processing.org/t/generative-collage-error/45714/2 "2025-02-06T08:55:07Z")

</div>

> [@jbanales](#):
>
> ```auto
> for (int i = 0; i < imageFileNames.length; i++) {
> String filename = imageFileNames[I];
> if (filename.indexOf("Store") == -1) {
> images.push("data/images/"+filename);
> }
> }
> 
> ```

It looks like one of your filenames is an empty string (`""`) try changing this to

```auto
  for (int i = 0; i < imageFileNames.length; i++) {
    String filename = imageFileNames[i]; // You had I instead of i
    if (filename.length() > 0 && filename.indexOf("Store") == -1) {
      images.push("data/images/"+filename);
    }
  }

```

Obviously I can’t guarentee this works because I can’t execute the code but I hope it works 😄

---

<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:** [February 6, 2025, 12:23pm UTC](https://discourse.processing.org/t/generative-collage-error/45714/3 "2025-02-06T12:23:21Z")

</div>

There’s a much simpler way to get all file paths within a folder using [**listPaths()**](http://processing.github.io/processing-javadocs/core/processing/core/PApplet.html#listPaths-java.lang.String-java.lang.String...-):

> [@Fading and Zoom (image slideshow)](https://discourse.processing.org/t/fading-and-zoom-image-slideshow/40812/30):
>
> This is a much simpler solution to load all images from a sketch’s “data/” folder via [listPaths()](http://processing.github.io/processing-javadocs/core/processing/core/PApplet.html#listPaths-java.lang.String-java.lang.String...-): file_folder

---

<div class="post-metadata">

**Author:** ![jbanales](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jbanales](https://discourse.processing.org/u/jbanales)\
**Post date:** [February 6, 2025, 11:44pm UTC](https://discourse.processing.org/t/generative-collage-error/45714/4 "2025-02-06T23:44:48Z")

</div>

Hello, I am not sure why it said [I] because in my sketch it says small i. However, the code you provided did not work. Oh well….

---

<div class="post-metadata">

**Author:** ![jbanales](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jbanales](https://discourse.processing.org/u/jbanales)\
**Post date:** [February 6, 2025, 11:46pm UTC](https://discourse.processing.org/t/generative-collage-error/45714/5 "2025-02-06T23:46:24Z")

</div>

> [@quark](#):
>
> ` if (filename.length(0) > 0 && filename.indexOf("Store") == -1)`

This is the new error:

The method length() in the type String is not applicable for the arguments (int)

---

<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:** [February 6, 2025, 11:58pm UTC](https://discourse.processing.org/t/generative-collage-error/45714/6 "2025-02-06T23:58:01Z")

</div>

> [@jbanales](#):
>
> The method length() in the type String is not applicable for the arguments (int)

See reference:

> **[length() / Reference](https://processing.org/reference/string_length_)**
>
> Returns the total number of characters included in the String as an integer number. People are often confused by the use of length() to get the size of a String and lengt…

Example:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/e/b/eb3c1923d0509c69265c768383681f443171ed2d.png)

`:)`

---

<div class="post-metadata">

**Author:** ![jbanales](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jbanales](https://discourse.processing.org/u/jbanales)\
**Post date:** [February 7, 2025, 1:45am UTC](https://discourse.processing.org/t/generative-collage-error/45714/7 "2025-02-07T01:45:07Z")

</div>

I don’t know how to fix this.

---

<div class="post-metadata">

**Author:** ![jbanales](https://avatars.discourse-cdn.com/v4/letter/j/3ec8ea/32.png) [@jbanales](https://discourse.processing.org/u/jbanales)\
**Post date:** [February 7, 2025, 3:02am UTC](https://discourse.processing.org/t/generative-collage-error/45714/8 "2025-02-07T03:02:10Z")

</div>

So it looks like the code runs if the sketch is on the desktop of my iMac, but not when it’s on an external drive.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [February 7, 2025, 9:36am UTC](https://discourse.processing.org/t/generative-collage-error/45714/9 "2025-02-07T09:36:18Z")

</div>

> [@jbanales](#):
>
> The method length() in the type String is not applicable for the arguments (int)

Sorry about that it was a typo 😄: and I have corrected my post.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [February 7, 2025, 9:41am UTC](https://discourse.processing.org/t/generative-collage-error/45714/10 "2025-02-07T09:41:42Z")

</div>

> [@jbanales](#):
>
> So it looks like the code runs if the sketch is on the desktop of my iMac, but not when it’s on an external drive.

1. Do you get an error message?
2. Have you checked the images file path is correct relative to your sketch code?
