# How to avoid image compression using the get() function?

**URL:** <https://discourse.processing.org/t/how-to-avoid-image-compression-using-the-get-function/32477>\
**Category:** Coding Questions\
**Created:** [September 28, 2021, 11:36am UTC](https://discourse.processing.org/t/how-to-avoid-image-compression-using-the-get-function/32477 "2021-09-28T11:36:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hspencer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hspencer/32/14206_2.png) [@hspencer](https://discourse.processing.org/u/hspencer)\
**Post date:** [September 28, 2021, 11:36am UTC](https://discourse.processing.org/t/how-to-avoid-image-compression-using-the-get-function/32477/1 "2021-09-28T11:36:51Z")

</div>

Hello!  
I’m using the get() function repeatedly and the resulting image degrades, apparently due to compression. Is there any way to get around this? Thanks!

```auto
/* animator tool */

let frames, span, current;

function setup() {
  span = 10;
  current = 0;
  createCanvas(500, 500);
  init();
}

function init(){
  frames = [];
  background(0);
  stroke(255);
  strokeWeight(5);
  for (let i = 0; i < span; i++) {
    let img = get();
    frames.push(img);
  }
}

function draw() {
  background(frames[current]);

  if (mouseIsPressed) {
    line(pmouseX, pmouseY, mouseX, mouseY);
  }

  frames[current] = get();
  current++;
  current %= span;
}

function keyTyped(){
  if(key === ' '){
    init();
  }
}

```

[link to live sketch](https://editor.p5js.org/hspencer/sketches/lqg_byogO)

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [September 28, 2021, 12:54pm UTC](https://discourse.processing.org/t/how-to-avoid-image-compression-using-the-get-function/32477/2 "2021-09-28T12:54:05Z")

</div>

Maybe draw to pgraphics and save the pgraphics

---

<div class="post-metadata">

**Author:** ![hspencer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hspencer/32/14206_2.png) [@hspencer](https://discourse.processing.org/u/hspencer)\
**Post date:** [September 28, 2021, 4:28pm UTC](https://discourse.processing.org/t/how-to-avoid-image-compression-using-the-get-function/32477/3 "2021-09-28T16:28:13Z")

</div>

Thanks, Paul! that definitely worked!

```auto
/* animator */

let frames; 
let span, current;

let prevTime, currentTime;
let speedSlider, colorFg, colorBg, weightSlider;

function setup() {
  frames = [];
  span = 10;
  current = 0;
  speedSlider = createSlider(0, 800, 0, 1);
  weightSlider = createSlider(0.25, 15, 3, 0.25);
  colorFg = createInput("#FFFFFF", "color");
  colorBg = createInput("#000000", "color");

  prevTime = 0;
  currentTime = 0;
  createCanvas(500, 500);
  background(0);

  for (let i = 0; i < span; i++) {
    let img = createGraphics(width, height);
    frames.push(img);
  }
}

function draw() {
  background(colorBg.value());
  image(frames[current], 0, 0);

  if (mouseIsPressed) {
    frames[current].stroke(colorFg.value());
    frames[current].strokeWeight(weightSlider.value());
    frames[current].line(pmouseX, pmouseY, mouseX, mouseY);
  }

  if (currentTime > prevTime + speedSlider.value()) {
    current++;
    current %= span;
    prevTime = millis();
  }
  currentTime = millis();
}

```

---

<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:** [September 28, 2021, 6:50pm UTC](https://discourse.processing.org/t/how-to-avoid-image-compression-using-the-get-function/32477/4 "2021-09-28T18:50:33Z")

</div>

If you ever do need to get the full resolution image from the canvas you can do so using `copy()` rather than `get()`. Here’s a stack overflow answer I posted recently on the topic: [p5.js - p5.Image from get() is drawn blurry due to pixelDensity issue p5js - Stack Overflow](https://stackoverflow.com/questions/69171227/p5-image-from-get-is-drawn-blurry-due-to-pixeldensity-issue-p5js/69180957#69180957)
