从粘贴板生成的截图为什么无法在浏览器里显示?

习惯使用cmd+shift+a微信截图,所以自己写了一个函数从粘贴板里的复制截图并保存到文件

但很疑惑这样生成的图片可以在emacs里浏览,也可以使用本地照片打开,却不能用浏览器查看,必须得本地照片打开并重新导出才行

另外这样生成的图片会很大,正常截图就100KB左右,使用这个函数生成的文件都大于1MB大小,有大佬研究过这个问题吗? 系统是macos+emacs-mac27.2

  (defun maple/org-download-yank()
    (interactive)
    (let ((file  org-download-screenshot-file)
          (image (get-text-property 0 'display (current-kill 0))))
      (if (or (not (consp image)) (not (eq (car image) 'image)))
          (org-download-yank)
        (with-temp-buffer
          (insert (plist-get (cdr image) :data))
          (let ((coding-system-for-write 'no-conversion))
            (write-region nil nil file)))
        (when (file-exists-p file)
          (org-download-image file)
          (delete-file file))))))

最终自己找到解决办法,通过file发现生成的截图是TIFF格式

TIFF image data, big-endian

所以利用系统的原有的工具把TIFF转换为PNG格式即可

(shell-command (format "tifftopnm %s | pnmtopng > %s" tiff file))
1 个赞