I'd like to be able to hit "Print Screen" on my keyboard and paste the images into a Steam chat, but as it stands that doesn't work because the screenshots created by Windows are too big in terms of filesize.
I wrote a simple program using this library that uses pngquant to optimize the image data in the clipboard and then replace the clipboard with it, but it doesn't work.
imageChannel := clipboard.Watch(context.Background(), clipboard.FmtImage)
copiedImage := <-imageChannel
fmt.Println("detected that an image was copied, compressing image...")
compressedImage, err := pngquant.CompressBytes(copiedImage, "1")
fmt.Println("original image size in bytes:", len(copiedImage))
fmt.Println("compressed image size in bytes:", len(compressedImage))
if err != nil {
panic(err)
}
fmt.Println("reading clipboard...")
fmt.Println(len(clipboard.Read(clipboard.FmtImage)))
fmt.Println("replacing clipboard...")
clipboard.Write(clipboard.FmtImage, compressedImage)
fmt.Println("reading clipboard...")
fmt.Println(len(clipboard.Read(clipboard.FmtImage)))
detected that an image was copied, compressing image...
original image size in bytes: 1947271
compressed image size in bytes: 1696311
reading clipboard...
1947271
replacing clipboard...
reading clipboard...
3881712
It'd be great if the original bytes could be written to the clipboard without being re-encoded (on Windows)