-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c648a7
commit d442ff0
Showing
26 changed files
with
157 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
apps/shinkai-visor/src/components/action-button/vr-notification.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 6 additions & 3 deletions
9
apps/shinkai-visor/src/components/image-capture/image-capture.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
apps/shinkai-visor/src/hooks/use-global-popup-chrome-message.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Buffer } from 'buffer'; | ||
|
||
export const blobToBase64 = (blob: Blob): Promise<string> => { | ||
const reader = new FileReader(); | ||
reader.readAsDataURL(blob); | ||
return new Promise((resolve) => { | ||
reader.onloadend = () => { | ||
resolve(reader.result as string); | ||
}; | ||
}); | ||
}; | ||
|
||
export const dataUrlToFile = ( | ||
dataUrl: string, | ||
filename: string, | ||
): File | undefined => { | ||
const arr = dataUrl.split(','); | ||
if (arr.length < 2) { | ||
return undefined; | ||
} | ||
const mimeArr = arr[0].match(/:(.*?);/); | ||
if (!mimeArr || mimeArr.length < 2) { | ||
return undefined; | ||
} | ||
const mime = mimeArr[1]; | ||
const buff = Buffer.from(arr[1], 'base64'); | ||
return new File([buff], filename, { type: mime }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { PixelCrop } from "react-image-crop" | ||
const TO_RADIANS = Math.PI / 180 | ||
|
||
export async function canvasPreview( | ||
image: HTMLImageElement, | ||
canvas: HTMLCanvasElement, | ||
crop: PixelCrop, | ||
scale = 1, | ||
rotate = 0, | ||
) { | ||
const ctx = canvas.getContext('2d') | ||
|
||
if (!ctx) { | ||
throw new Error('No 2d context') | ||
} | ||
|
||
const scaleX = image.naturalWidth / image.width | ||
const scaleY = image.naturalHeight / image.height | ||
// devicePixelRatio slightly increases sharpness on retina devices | ||
// at the expense of slightly slower render times and needing to | ||
// size the image back down if you want to download/upload and be | ||
// true to the images natural size. | ||
const pixelRatio = window.devicePixelRatio | ||
// const pixelRatio = 1 | ||
|
||
canvas.width = Math.floor(crop.width * scaleX * pixelRatio) | ||
canvas.height = Math.floor(crop.height * scaleY * pixelRatio) | ||
|
||
ctx.scale(pixelRatio, pixelRatio) | ||
ctx.imageSmoothingQuality = 'high' | ||
|
||
const cropX = crop.x * scaleX | ||
const cropY = crop.y * scaleY | ||
|
||
const rotateRads = rotate * TO_RADIANS | ||
const centerX = image.naturalWidth / 2 | ||
const centerY = image.naturalHeight / 2 | ||
|
||
ctx.save() | ||
|
||
// 5) Move the crop origin to the canvas origin (0,0) | ||
ctx.translate(-cropX, -cropY) | ||
// 4) Move the origin to the center of the original position | ||
ctx.translate(centerX, centerY) | ||
// 3) Rotate around the origin | ||
ctx.rotate(rotateRads) | ||
// 2) Scale the image | ||
ctx.scale(scale, scale) | ||
// 1) Move the center of the image to the origin (0,0) | ||
ctx.translate(-centerX, -centerY) | ||
ctx.drawImage( | ||
image, | ||
0, | ||
0, | ||
image.naturalWidth, | ||
image.naturalHeight, | ||
0, | ||
0, | ||
image.naturalWidth, | ||
image.naturalHeight, | ||
) | ||
|
||
ctx.restore() | ||
} | ||
|
||
export const canvasToBlob = (canvas: HTMLCanvasElement, type: 'image/jpeg' = 'image/jpeg', quality: number = 0.92): Promise<Blob | null> => { | ||
return new Promise((resolve) => { | ||
canvas.toBlob(resolve, 'image/jpeg', 0.5); | ||
}) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Oops, something went wrong.