From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: I'm looking for a way to paste images directly from the clipboard into Emacs Date: Tue, 12 Nov 2024 03:37:52 +0300 Message-ID: References: <86v7wtil31.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25051"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/2.2.12 (2023-09-09) Cc: help-gnu-emacs@gnu.org To: Eli Zaretskii Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Tue Nov 12 01:39:19 2024 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tAewA-0006KU-EE for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 12 Nov 2024 01:39:18 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tAeva-0005VS-6C; Mon, 11 Nov 2024 19:38:42 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tAevY-0005VC-QY for help-gnu-emacs@gnu.org; Mon, 11 Nov 2024 19:38:41 -0500 Original-Received: from stw1.rcdrun.com ([217.170.207.13]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tAevW-0002JI-RM; Mon, 11 Nov 2024 19:38:40 -0500 Original-Received: from localhost ([::ffff:41.75.191.23]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 00000000001778E3.000000006732A369.000B3779; Mon, 11 Nov 2024 17:38:01 -0700 Mail-Followup-To: Eli Zaretskii , help-gnu-emacs@gnu.org Content-Disposition: inline In-Reply-To: <86v7wtil31.fsf@gnu.org> Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:148322 Archived-At: * Eli Zaretskii [2024-11-11 23:16]: > > Date: Mon, 11 Nov 2024 22:26:39 +0300 > > From: Jean Louis > > > > I'm looking for a way to paste images directly from the clipboard into Emacs. If an image is detected, I would like to perform various operations on it, such as saving it to a file or recording it. Is there an existing method or package in Emacs that can facilitate this functionality? Any guidance or tips would be greatly appreciated! > > Emacs 30 and later has the new command yank-media for that purpose. That is very nice. I have done this and now it works well, I just need to make more extensions. I can see multiple image MIME types being offered from various programs. (defun hyperscope-yank-media-handler (mime-type data) "HANDLER function to be registered with `yank-media-handler'." (let* ((extension (cond ((and (string-match "image" (symbol-name mime-type)) (string-match "jpeg" (symbol-name mime-type))) ".jpg") ((and (string-match "image" (symbol-name mime-type)) (string-match "png" (symbol-name mime-type))) ".png") (t (rcd-warning-message "No option for MIME type: %s" (symbol-name mime-type))))) (data-file (concat (file-name-as-directory (getenv "TMPDIR")) "TEMP-IMAGE-" (rcd-timestamp-date-time) "-" (rcd-random-word 4) extension))) (string-to-file-force data data-file) (hyperscope-store-files nil (list data-file)) (rcd-message "Stored %s as file %s" (symbol-name mime-type) data-file))) (defun hyperscope-capture-clipboard-media () "Capture any clipboard image into the Hyperscope Dynamic Knowledge Repository." (interactive) (with-temp-buffer (yank-media-handler "image/.*" 'hyperscope-yank-media-handler) (yank-media))) Jean Louis