Replies: 5 comments
-
|
Is the purpose of this feature to crop the element? |
Beta Was this translation helpful? Give feedback.
-
是的 |
Beta Was this translation helpful? Give feedback.
-
|
Good! Ok let me see if it could be added in the snapDOM core or delegated to a custom plugin. |
Beta Was this translation helpful? Give feedback.
-
|
I needed cropping myself. Ended up just sending the PNG through this: async function cropImageToPng(
image: HTMLImageElement,
width: number,
height: number,
scale: number = 1
): Promise<string> {
// Create offscreen canvas with final output size
const canvas = new OffscreenCanvas(width, height);
const ctx = canvas.getContext('2d')!;
// Calculate crop size based on scale
const cropWidth = width * scale;
const cropHeight = height * scale;
// Draw cropped portion from top-left (0,0) of source image, scaled down to fit canvas
ctx.drawImage(
image,
0,
0,
cropWidth,
cropHeight, // Source rectangle (larger crop area)
0,
0,
width,
height // Destination rectangle (scaled down to output size)
);
// Convert to PNG blob
const blob = await canvas.convertToBlob({ type: 'image/png' });
// Convert blob to data URL
return new Promise<string>((resolve) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result as string);
reader.readAsDataURL(blob);
});
} |
Beta Was this translation helpful? Give feedback.
-
|
Please se #113 , I made a simple plugin to crop a capure |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
https://html2canvas.hertzen.com/configuration
如何才能实现 html2canvas 中的x y轴上的位置偏移呢
Beta Was this translation helpful? Give feedback.
All reactions