# Fill text color with the same color of preload image

**URL:** <https://discourse.processing.org/t/fill-text-color-with-the-same-color-of-preload-image/32716>\
**Category:** Coding Questions\
**Created:** [October 9, 2021, 11:41pm UTC](https://discourse.processing.org/t/fill-text-color-with-the-same-color-of-preload-image/32716 "2021-10-09T23:41:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tropicalpoison](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@tropicalpoison](https://discourse.processing.org/u/tropicalpoison)\
**Post date:** [October 9, 2021, 11:41pm UTC](https://discourse.processing.org/t/fill-text-color-with-the-same-color-of-preload-image/32716/1 "2021-10-09T23:41:33Z")

</div>

Hello all,  
I want to fill a text’s (avg 450 words or more) color with the same color of preload image on canvas in P5js.  
Actually, I am trying to recreate this image with the same colors as the text I wrote.  
Is anybody can help me with how to do that?

---

<div class="post-metadata">

**Author:** ![KumuPaul](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kumupaul/32/13072_2.png) [@KumuPaul](https://discourse.processing.org/u/KumuPaul)\
**Post date:** [October 10, 2021, 1:57am UTC](https://discourse.processing.org/t/fill-text-color-with-the-same-color-of-preload-image/32716/2 "2021-10-10T01:57:10Z")

</div>

Cross post from [StackOverflow](https://stackoverflow.com/questions/69510830/how-to-fill-text-color-with-the-same-preload-image-color-in-p5js). Please let us know when you are cross posting.

---

<div class="post-metadata">

**Author:** ![micuat](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micuat/32/19407_2.png) [@micuat](https://discourse.processing.org/u/micuat)\
**Post date:** [October 10, 2021, 10:19am UTC](https://discourse.processing.org/t/fill-text-color-with-the-same-color-of-preload-image/32716/3 "2021-10-10T10:19:37Z")

</div>

[the answer by Luke Garrigan on stackoverflow](https://stackoverflow.com/a/69513049) solves the problem

```auto
let img;
function preload() {
  img = loadImage('img.jpg');
}

function setup() {
  createCanvas(400, 400);
  image(img, 0, 0);
  let c = get(0, 0);
  fill(c);
}

function draw() {
  background(0);
  image(img, 0, 0);
  textSize(20);
  text('I am the same colour', 100, 350);
}

```

however it would be even better if you sample the color directly from the image by `img.get(0, 0)`.  
(oh I don’t like cross posting because of this reason. I don’t have an account on stackoverflow so I’m sharing the solution here, but I hate that the information is scattered everywhere…)

---

<div class="post-metadata">

**Author:** ![tropicalpoison](https://avatars.discourse-cdn.com/v4/letter/t/22d042/32.png) [@tropicalpoison](https://discourse.processing.org/u/tropicalpoison)\
**Post date:** [October 10, 2021, 10:46am UTC](https://discourse.processing.org/t/fill-text-color-with-the-same-color-of-preload-image/32716/4 "2021-10-10T10:46:41Z")

</div>

sorry about that, I will if I did again.
