Skip to content

Commit

Permalink
fixed the issue processing#6114
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav-1306 committed Sep 30, 2023
1 parent 63f94b0 commit c4f10ac
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/image/p5.Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,32 @@ p5.Image = class {
this.pixels = [];
}

/**
* Set the pixel density of the image.
*
* @method setPixelDensity
* @param {Number} density - The pixel density to set.
* @example
* <div><code>
* let img = new p5.Image(100, 100);
* img.setPixelDensity(2);
* </code></div>
*/
setPixelDensity(density) {
if (density <= 0) {
console.error('Pixel density must be greater than 0.');
return;
}

this._pixelDensity = density;

// Adjust canvas dimensions based on pixel density
this.canvas.width = this.width * density;
this.canvas.height = this.height * density;

// Update the drawing context
this.drawingContext = this.canvas.getContext('2d');
}
/**
* Helper function for animating GIF-based images with time
*/
Expand Down

0 comments on commit c4f10ac

Please sign in to comment.