toImageData = (img, { width = Infinity, height = Infinity } = {}) => {
let { naturalWidth, naturalHeight } = img;
let r = compute_ratio(naturalWidth, naturalHeight, width, height);
[width, height] = [naturalWidth, naturalHeight].map((d) => d / r);
const ctx = context2d({ width, height });
ctx.drawImage(img, 0, 0, width, height);
return ctx.getImageData(0, 0, width, height);
}