# Why is my result stretched?

**URL:** <https://discourse.processing.org/t/why-is-my-result-stretched/26051>\
**Category:** Coding Questions\
**Created:** [December 8, 2020, 4:16pm UTC](https://discourse.processing.org/t/why-is-my-result-stretched/26051 "2020-12-08T16:16:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![olaf000olaf](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/olaf000olaf/32/11295_2.png) [@olaf000olaf](https://discourse.processing.org/u/olaf000olaf)\
**Post date:** [December 8, 2020, 4:16pm UTC](https://discourse.processing.org/t/why-is-my-result-stretched/26051/1 "2020-12-08T16:16:27Z")

</div>

[https://www.openprocessing.org/sketch/1037242](https://www.openprocessing.org/sketch/1037242) here is my code and this is the tutorial I followed [https://www.youtube.com/watch?v=rNqaw8LT2ZU](https://www.youtube.com/watch?v=rNqaw8LT2ZU) and this is the original image

 ![black and white](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/8/84b0a3d5a66b9ab1c99a4014611a0099d46a2690.jpeg)

---

<div class="post-metadata">

**Author:** ![ErraticGenerator](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/erraticgenerator/32/11304_2.png) [@ErraticGenerator](https://discourse.processing.org/u/ErraticGenerator)\
**Post date:** [December 8, 2020, 5:24pm UTC](https://discourse.processing.org/t/why-is-my-result-stretched/26051/2 "2020-12-08T17:24:09Z")

</div>

Your canvas size and image size is different, so when you go over every pixel of your image, you need to refer to `img.width` and `img.height` instead of canvas width and height.

```auto
for (let x = 0; x < img.width; x = x + 1) {
    for (let y = 0; y < img.height; y = y + 1) {
		 let index = (x + y * img.width) * 4;
    }
}

```

---

<div class="post-metadata">

**Author:** ![olaf000olaf](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/olaf000olaf/32/11295_2.png) [@olaf000olaf](https://discourse.processing.org/u/olaf000olaf)\
**Post date:** [December 8, 2020, 5:33pm UTC](https://discourse.processing.org/t/why-is-my-result-stretched/26051/3 "2020-12-08T17:33:57Z")

</div>

thx \<3 I’m still very new
