Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- imageSource = http://abc/myimage.jpg
- extractedFaces = array of face objects, each object looks like {boundingBox: [], ...}
- originalSize = original size of image, looks like {height: 640px, width: 480px} only height is needed here
- renderExtractedFaces = (imageSource, extractedFaces, originalSize) => {
- let results = []
- extractedFaces.forEach((face, i) => {
- let x = face.boundingBox[0]
- let y = face.boundingBox[1]
- let w = face.boundingBox[2] - x
- let h = face.boundingBox[3] - y
- let newX = x/h*100
- let newY = y/h*100
- let newW = w/h*100
- let newH = h/h*100
- results.push(
- <div key={`face-${i}`}>
- <div
- style={{
- backgroundImage: `url("${imageSource}")`,
- backgroundSize: `auto ${originalSize.height/h*100}px`,
- backgroundPositionX: `-${newX}px`,
- backgroundPositionY: `-${newY}px`,
- width: `${newW}px`,
- height: `${newH}px`
- }}
- />
- </div>
- )
- })
- return results
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement