MCPcopy Create free account
hub / github.com/Roy3838/Observer / cropDataUrl

Function cropDataUrl

app/src/utils/screenCapture.ts:52–64  ·  view source on GitHub ↗
(
  dataUrl: string,
  crop: CropConfig,
)

Source from the content-addressed store, hash-verified

50 * iteration (same resolveCrop). Used to preview what a crop will send to the model.
51 */
52export async function cropDataUrl(
53 dataUrl: string,
54 crop: CropConfig,
55): Promise<{ dataUrl: string; width: number; height: number }> {
56 const bitmap = await createImageBitmap(await (await fetch(dataUrl)).blob());
57 const px = resolveCrop(crop, bitmap.width, bitmap.height);
58 const canvas = document.createElement('canvas');
59 canvas.width = px.width;
60 canvas.height = px.height;
61 canvas.getContext('2d')!.drawImage(bitmap, px.x, px.y, px.width, px.height, 0, 0, px.width, px.height);
62 bitmap.close();
63 return { dataUrl: canvas.toDataURL('image/png'), width: px.width, height: px.height };
64}
65
66export function removeAgentCrops(agentId: string): void {
67 agentCropConfigs.delete(agentId);

Callers 1

previewAgentCropFunction · 0.90

Calls 1

resolveCropFunction · 0.90

Tested by

no test coverage detected