File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { existsSync , mkdirSync , readFileSync , writeFileSync } from 'node:fs' ;
22import path from 'node:path' ;
33import type { PlanningAIResponse , Rect } from '@midscene/core' ;
4- import { NodeType } from '@midscene/shared/constants' ;
54import {
6- compositeElementInfoImg ,
5+ annotateRects ,
76 imageInfoOfBase64 ,
87 localImg2Base64 ,
98} from '@midscene/shared/img' ;
109import { WebPageContextParser } from '@midscene/web' ;
1110
11+ export { annotateRects } ;
12+
1213export const repeatTime = 1 ;
1314
1415export type TestCase = {
@@ -220,26 +221,3 @@ export async function buildContext(pageName: string) {
220221 const context = await WebPageContextParser ( fakePage as any , { } ) ;
221222 return context ;
222223}
223-
224- export async function annotateRects (
225- imgBase64 : string ,
226- rects : Rect [ ] ,
227- prompt ?: string ,
228- ) {
229- const markedImage = await compositeElementInfoImg ( {
230- inputImgBase64 : imgBase64 ,
231- elementsPositionInfo : rects . map ( ( rect , index ) => {
232- return {
233- id : `rect-${ index } ` ,
234- rect,
235- indexId : index + 1 ,
236- attributes : { nodeType : NodeType . CONTAINER } ,
237- content : '' ,
238- center : [ rect . left + rect . width / 2 , rect . top + rect . height / 2 ] ,
239- } ;
240- } ) ,
241- annotationPadding : 0 ,
242- prompt,
243- } ) ;
244- return markedImage ;
245- }
Original file line number Diff line number Diff line change 11import assert from 'node:assert' ;
22import type { PhotonImage as PhotonImageType } from '@silvia-odwyer/photon-node' ;
3+ import { NodeType } from '../constants' ;
34import type { BaseElement , Rect } from '../types' ;
45import getPhoton from './get-photon' ;
5- import { bufferFromBase64 , imageInfoOfBase64 } from './info' ;
66import { photonFromBase64 , photonToBase64 } from './transform' ;
77
88// Simple 5x7 bitmap font for digits 0-9
@@ -548,3 +548,26 @@ export const processImageElementInfo = async (options: {
548548 compositeElementInfoImgWithoutTextBase64,
549549 } ;
550550} ;
551+
552+ export async function annotateRects (
553+ imgBase64 : string ,
554+ rects : Rect [ ] ,
555+ prompt ?: string ,
556+ ) {
557+ const markedImage = await compositeElementInfoImg ( {
558+ inputImgBase64 : imgBase64 ,
559+ elementsPositionInfo : rects . map ( ( rect , index ) => {
560+ return {
561+ id : `rect-${ index } ` ,
562+ rect,
563+ indexId : index + 1 ,
564+ attributes : { nodeType : NodeType . CONTAINER } ,
565+ content : '' ,
566+ center : [ rect . left + rect . width / 2 , rect . top + rect . height / 2 ] ,
567+ } ;
568+ } ) ,
569+ annotationPadding : 0 ,
570+ prompt,
571+ } ) ;
572+ return markedImage ;
573+ }
Original file line number Diff line number Diff line change 1- export {
2- imageInfoOfBase64 ,
3- bufferFromBase64 ,
4- isValidPNGImageBuffer ,
5- } from './info' ;
1+ export { imageInfoOfBase64 , isValidPNGImageBuffer } from './info' ;
62export {
73 resizeAndConvertImgBuffer ,
84 resizeImgBase64 ,
@@ -19,5 +15,9 @@ export {
1915 parseBase64 ,
2016 createImgBase64ByFormat ,
2117} from './transform' ;
22- export { processImageElementInfo , compositeElementInfoImg } from './box-select' ;
18+ export {
19+ processImageElementInfo ,
20+ compositeElementInfoImg ,
21+ annotateRects ,
22+ } from './box-select' ;
2323export { drawBoxOnImage , savePositionImg } from './draw-box' ;
Original file line number Diff line number Diff line change 11import assert from 'node:assert' ;
2- import { Buffer } from 'node:buffer' ;
32import type { Size } from '../types' ;
43import getPhoton from './get-photon' ;
54
@@ -25,11 +24,6 @@ export async function imageInfoOfBase64(
2524 return { width, height } ;
2625}
2726
28- export async function bufferFromBase64 ( imageBase64 : string ) : Promise < Buffer > {
29- const base64Data = imageBase64 . replace ( / ^ d a t a : i m a g e \/ \w + ; b a s e 6 4 , / , '' ) ;
30- return Buffer . from ( base64Data , 'base64' ) ;
31- }
32-
3327/**
3428 * Check if the Buffer is a valid PNG image
3529 * @param buffer The Buffer to check
You can’t perform that action at this time.
0 commit comments