unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Keith David Bershatsky <esq@lawlist.com>
To: 26432@debbugs.gnu.org
Subject: bug#26432: Acknowledgement (image-dired: Adding support for PDF thumbnails.)
Date: Mon, 10 Apr 2017 21:01:50 -0700	[thread overview]
Message-ID: <m21sszh9sh.wl%esq@lawlist.com> (raw)
In-Reply-To: <m2vaqcjpu9.wl%esq@lawlist.com>

In my own setup, I added the ability to detect the image size of the thumbnails and compare it to the current value of the image-dired width/height variables so that a new thumbnail will be created if the width/height of a stored cache thumbnail is different the current call.  For example, multiple thumbnails might be 100 pixels, but perhaps I want to see an 800 thumbnail of just the selected file.  This modification enables me to change the thumbnail image programmatically:

(defun image-dimensions (filename)
  (let* ((convert-program image-dired-cmd-create-thumbnail-program)
         (raw-dimensions
           (shell-command-to-string
             (concat convert-program " " "\"" filename "\"" " -ping -format \"%w x %h\" info:")))
         (list-dimensions
           (delete "x" (split-string raw-dimensions))))
    (cons
      (string-to-number (car list-dimensions))
      (string-to-number (cadr list-dimensions)))))

;;; ALTERNATIVE VERSION:

(defun image-dired-display-thumbs (&optional arg append do-not-pop)
  "Display thumbnails of all marked files, in `image-dired-thumbnail-buffer'.
If a thumbnail image does not exist for a file, it is created on the
fly.  With prefix argument ARG, display only thumbnail for file at
point (this is useful if you have marked some files but want to show
another one).

Recommended usage is to split the current frame horizontally so that
you have the dired buffer in the left window and the
`image-dired-thumbnail-buffer' buffer in the right window.

With optional argument APPEND, append thumbnail to thumbnail buffer
instead of erasing it first.

Optional argument DO-NOT-POP controls if `pop-to-buffer' should be
used or not.  If non-nil, use `display-buffer' instead of
`pop-to-buffer'.  This is used from functions like
`image-dired-next-line-and-display' and
`image-dired-previous-line-and-display' where we do not want the
thumbnail buffer to be selected."
  (interactive "P")
  (let ((buf (image-dired-create-thumbnail-buffer))
        thumb-name files dired-buf)
    (if arg
        (setq files (list (dired-get-filename)))
      (setq files (dired-get-marked-files)))
    (setq dired-buf (current-buffer))
    (with-current-buffer buf
      (let ((inhibit-read-only t))
        (if (not append)
            (erase-buffer)
          (goto-char (point-max)))
        (mapc
         (lambda (curr-file)
           (cond
             ((string-match (image-file-name-regexp) curr-file)
               (let* ((thumb-name (image-dired-thumb-name curr-file))
                      (thumbnail-dimensions
                        (when (file-exists-p thumb-name)
                          (image-dimensions thumb-name))))
                 (if (and
                        ;;; The goal is to move on to `image-dired-create-thumb' IF
                        ;;; the thumbnail exists and is the wrong size, or it does not exist.
                        (or (and (file-exists-p thumb-name)
                                 (not (or (= image-dired-thumb-width
                                             (car thumbnail-dimensions))
                                          (= image-dired-thumb-height
                                             (cdr thumbnail-dimensions))))
                                 (progn
                                   (clear-image-cache)
                                   'create-new-image))
                            (not (file-exists-p thumb-name)))
                        (not (= 0 (image-dired-create-thumb curr-file thumb-name))))
                   (message "Thumb could not be created for file %s" curr-file)
                   (image-dired-insert-thumbnail thumb-name curr-file dired-buf))))
             ((string-match "\\.\\(PDF\\)\\'" curr-file)
               (let* ((absolute-basename (file-name-sans-extension curr-file))
                      (png-filename (concat absolute-basename ".png"))
                      (pdf-first-page-filename (concat curr-file "[0]"))
                      (thumb-name (image-dired-thumb-name png-filename))
                      (thumbnail-dimensions
                        (when (file-exists-p thumb-name)
                          (image-dimensions thumb-name))))
                 (if (and
                        ;;; The goal is to move on to `image-dired-create-thumb' IF
                        ;;; the thumbnail exists and is the wrong size, or it does not exist.
                        (or (and (file-exists-p thumb-name)
                                 (not (or (= image-dired-thumb-width
                                             (car thumbnail-dimensions))
                                          (= image-dired-thumb-height
                                             (cdr thumbnail-dimensions))))
                                 (progn
                                   (clear-image-cache)
                                   'create-new-image))
                            (not (file-exists-p thumb-name)))
                        (not (= 0 (image-dired-create-thumb pdf-first-page-filename thumb-name))))
                     (message "Thumb could not be created for file %s" pdf-first-page-filename)
                   (image-dired-insert-thumbnail thumb-name pdf-first-page-filename dired-buf))))
             (t
               (message "%s does not match `image-file-name-regexp'" curr-file))))
         files))
      (cond ((eq 'dynamic image-dired-line-up-method)
             (image-dired-line-up-dynamic))
            ((eq 'fixed image-dired-line-up-method)
             (image-dired-line-up))
            ((eq 'interactive image-dired-line-up-method)
             (image-dired-line-up-interactive))
            ((eq 'none image-dired-line-up-method)
             nil)
            (t
             (image-dired-line-up-dynamic))))
    (if do-not-pop
        (display-buffer image-dired-thumbnail-buffer)
      (pop-to-buffer image-dired-thumbnail-buffer))))





  reply	other threads:[~2017-04-11  4:01 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-10 14:32 bug#26432: image-dired: Adding support for PDF thumbnails Keith David Bershatsky
2017-04-11  4:01 ` Keith David Bershatsky [this message]
2017-04-11 18:05   ` bug#26432: Acknowledgement (image-dired: Adding support for PDF thumbnails.) Glenn Morris
2019-09-29 12:11     ` Lars Ingebrigtsen
2019-09-29 16:57       ` Keith David Bershatsky
2019-10-23 10:03         ` Lars Ingebrigtsen
2019-10-24  3:27 ` Keith David Bershatsky
2019-10-24 11:52   ` Lars Ingebrigtsen
2020-08-04  9:12     ` Lars Ingebrigtsen
2021-10-20 15:38       ` bug#26432: image-dired: Adding support for PDF thumbnails Stefan Kangas
2022-09-16  0:39     ` Stefan Kangas
2022-09-16  3:21 ` Keith David Bershatsky
2022-09-16  6:02   ` Eli Zaretskii
2022-09-16 20:52 ` Stefan Kangas
2022-09-21 14:06   ` Stefan Kangas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m21sszh9sh.wl%esq@lawlist.com \
    --to=esq@lawlist.com \
    --cc=26432@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).