Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
zoom-image-data
Advanced tools
将指定宽高的图像缓冲区数据输出到另一宽高的图像缓冲区
npm install zoom-image-data
new zoomImageData(
param: {
// 输入宽
inw: number,
// 输入高
inh: number,
// 输出宽
outw: number,
// 输出高
outh: number,
// 输出缓冲区单位像素宽高比;默认值:1
cellRatio?: number,
// 输出缓冲区单位像素对应值;默认值:10
cellWH?: number,
// 是否显示分割线;默认值:false
splitCell?: number,
// 显示分割线时输出缓冲区对应的像素值;默认值:2
splitCellSize?: number,
// 输入图像缓冲区
inData: ArrayBuffer,
// 输出图像缓冲区
outData: ArrayBuffer,
}
) => zoomImageData
/**
* 平移
* @param silent 是否更新outData缓冲区
*/
translate(dx: number, dy: number, silent?: boolean) => void
/**
* 平移
* @param silent 是否更新outData缓冲区
*/
zoom(cx: number, cy: number, ratio: number, silent?: boolean) => void
/**
* 平移
* @param silent 是否更新outData缓冲区
*/
resize(silent?: boolean) => void
updateMatrix(scale: number, dx: number, dy: number) => void
inCoorIsIn(x: number, y: number) => boolean
outCoorIsIn(x: number, y: number) => boolean
transInToOut(coors: number[]) => number[]
transOutToIn(coors: number[]) => number[]
update() => number[]
zoom-image-data单元像素可以不等比转移到输出图像缓冲区中,且支持放大到一定倍率之后显示分割线
以下为将一个原宽高为64*64的图像按宽高比为2绘制到指定宽高canvas元素。示例网站
<canvas id="canvas"></canvas>
html,
body {
width: 100%;
height: 100%;
margin: 0;
overflow: hidden;
}
import { zoomImageData } from 'zoom-image-data';
window.onload = function () {
const canvas = document.getElementById('canvas');
const inw = 64;
const inh = 64;
const inData = new ArrayBuffer(inw * inh * 4);
const outw = document.body.clientWidth;
const outh = document.body.clientHeight;
const outImageData = new ImageData(outw, outh);
canvas.width = outw;
canvas.height = outh;
const ctx = canvas.getContext('2d');
const transferImageData = new ZoomImageData({
inw,
inh,
inData,
outw,
outh,
outData: outImageData.data.buffer,
cellRatio: 2,
cellWH: 4,
splitCell: true,
splitCellSize: 10,
})
let isDirty = true;
fillInData();
requestAnimationFrame(update);
/**
* 更新画布
*/
function update() {
requestAnimationFrame(update);
if (!isDirty) return;
isDirty = false
transferImageData.update();
ctx.putImageData(outImageData, 0, 0);
}
/**
* 初始化inData
*/
function fillInData() {
const { inw, inh, inData } = transferImageData;
for (let y = 0; y < inh; y++) {
const s = 4291611705 - y * 512;
for (let x = 0; x < inw; x++) {
inData[y * inw + x] = s + x * 3;
}
}
}
/**
* 获取鼠标相对于canvas的坐标
*/
function getPosition(e) {
let rect = canvas.getBoundingClientRect();
return [e.pageX - rect.left, e.pageY - rect.top];
}
/**
* 重置
*/
document.addEventListener('keyup', function (e) {
transferImageData.resize();
isDirty = true;
})
/**
* 缩放
*/
canvas.addEventListener('wheel', function (e) {
const coor = getPosition(e);
transferImageData.zoom(coor[0], coor[1], e.deltaY < 0 ? 1.1 : 0.9);
isDirty = true;
})
/**
* 平移
*/
let pos;
canvas.addEventListener('mousedown', function (e) {
pos = getPosition(e);
document.addEventListener('mousemove', mousemove)
document.addEventListener('mouseup', mouseup)
})
function mousemove(e) {
const cur = getPosition(e);
transferImageData.translate(cur[0] - pos[0], cur[1] - pos[1]);
pos = cur;
isDirty = true;
}
function mouseup() {
document.removeEventListener('mousemove', mousemove)
document.removeEventListener('mouseup', mouseup)
}
}
FAQs
zoom-image-data
The npm package zoom-image-data receives a total of 3 weekly downloads. As such, zoom-image-data popularity was classified as not popular.
We found that zoom-image-data demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.