MCPcopy Create free account
hub / github.com/32comic/image2pixel-web / pixelateToWidth

Method pixelateToWidth

pixelizer.js:646–659  ·  view source on GitHub ↗

* 像素化到指定宽度

(sourceCanvas, targetWidth)

Source from the content-addressed store, hash-verified

644 * 像素化到指定宽度
645 */
646 pixelateToWidth(sourceCanvas, targetWidth) {
647 const aspectRatio = sourceCanvas.height / sourceCanvas.width;
648 const targetHeight = Math.round(targetWidth * aspectRatio);
649
650 const targetCanvas = document.createElement('canvas');
651 targetCanvas.width = targetWidth;
652 targetCanvas.height = targetHeight;
653 const targetCtx = targetCanvas.getContext('2d');
654
655 targetCtx.imageSmoothingEnabled = false;
656 targetCtx.drawImage(sourceCanvas, 0, 0, targetWidth, targetHeight);
657
658 return targetCanvas;
659 }
660
661 /**
662 * 应用颜色量化

Callers 2

processAutoModeMethod · 0.95
processManualModeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected