Skip to content

Instantly share code, notes, and snippets.

View xiangrenya's full-sized avatar

RenYa Xiang xiangrenya

  • SuZhou
  • 07:44 (UTC +08:00)
View GitHub Profile
function extractPartOfImage(img, { x, y, width, height }) {
const dpi = 2;
const el = document.createElement("canvas");
el.width = width * dpi;
el.height = height * dpi;
const ctx = el.getContext("2d");
ctx.drawImage(
img,
x * dpi,
y * dpi,