( dataUrl: string, crop: CropConfig, )
| 50 | * iteration (same resolveCrop). Used to preview what a crop will send to the model. |
| 51 | */ |
| 52 | export 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 | |
| 66 | export function removeAgentCrops(agentId: string): void { |
| 67 | agentCropConfigs.delete(agentId); |
no test coverage detected