Skip to content

Instantly share code, notes, and snippets.

@manicai
Last active January 8, 2024 17:17
Show Gist options
  • Save manicai/f6ffb5667d6ed2f0930d6faf53cbc1d7 to your computer and use it in GitHub Desktop.
Save manicai/f6ffb5667d6ed2f0930d6faf53cbc1d7 to your computer and use it in GitHub Desktop.
Dumping image data from Chrome
// Typescript
export function dump_image(image: ImageData) {
const canvas = document.createElement("canvas") as HTMLCanvasElement;
canvas.width = image.width;
canvas.height = image.height;
canvas.getContext("2d")!.putImageData(image, 0, 0);
return canvas.toDataURL();
}
/* Then a Bash script
#!/bin/bash
OUTPUT_FILE="$1"
if [ -z "${OUTPUT_FILE}" ]
then
>&2 echo "Usage: $0 <output_file>"
exit 1
fi
xclip -o | sed "s/data:image\/png;base64,//gi" | base64 -d > "${OUTPUT_FILE}"
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment