diff options
| author | Mark Oteiza | 2016-12-15 19:55:47 -0500 |
|---|---|---|
| committer | Mark Oteiza | 2016-12-15 19:55:47 -0500 |
| commit | 7ec55a189c45b29efdf68d2bc1a8b0d865aa9b6b (patch) | |
| tree | 2c2bbf692bae1fc0ceed4fb77fc4c2844041e1fc | |
| parent | 5942af614133000a42b3b11f963a30c2b987272e (diff) | |
| download | emacs-7ec55a189c45b29efdf68d2bc1a8b0d865aa9b6b.tar.gz emacs-7ec55a189c45b29efdf68d2bc1a8b0d865aa9b6b.zip | |
Teach image-dired to also generate large thumbs
* lisp/image-dired.el (image-dired-thumbnail-storage): Add
standard-large option.
(image-dired-thumb-size): Add condition for standard-large storage.
(image-dired-insert-thumbnail): Check for new option. Change
thumbnail path conditionally.
(image-dired-thumb-size): New function.
(image-dired-create-thumb, image-dired-line-up-dynamic): Use it.
| -rw-r--r-- | lisp/image-dired.el | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/lisp/image-dired.el b/lisp/image-dired.el index 60b7a5dbb65..63e3aa9264a 100644 --- a/lisp/image-dired.el +++ b/lisp/image-dired.el | |||
| @@ -180,8 +180,9 @@ means that each thumbnail is stored in a subdirectory called | |||
| 180 | stored and generated according to the Thumbnail Managing Standard | 180 | stored and generated according to the Thumbnail Managing Standard |
| 181 | that allows sharing of thumbnails across different programs." | 181 | that allows sharing of thumbnails across different programs." |
| 182 | :type '(choice :tag "How to store thumbnail files" | 182 | :type '(choice :tag "How to store thumbnail files" |
| 183 | (const :tag "Thumbnail Managing Standard" standard) | ||
| 184 | (const :tag "Use image-dired-dir" use-image-dired-dir) | 183 | (const :tag "Use image-dired-dir" use-image-dired-dir) |
| 184 | (const :tag "Thumbnail Managing Standard (normal 128x128)" standard) | ||
| 185 | (const :tag "Thumbnail Managing Standard (large 256x256)" standard-large) | ||
| 185 | (const :tag "Per-directory" per-directory)) | 186 | (const :tag "Per-directory" per-directory)) |
| 186 | :group 'image-dired) | 187 | :group 'image-dired) |
| 187 | 188 | ||
| @@ -399,7 +400,10 @@ Used by `image-dired-gallery-generate' to leave out \"hidden\" images." | |||
| 399 | :group 'image-dired) | 400 | :group 'image-dired) |
| 400 | 401 | ||
| 401 | (defcustom image-dired-thumb-size | 402 | (defcustom image-dired-thumb-size |
| 402 | (if (eq 'standard image-dired-thumbnail-storage) 128 100) | 403 | (cond |
| 404 | ((eq 'standard image-dired-thumbnail-storage) 128) | ||
| 405 | ((eq 'standard-large image-dired-thumbnail-storage) 256) | ||
| 406 | (t 100)) | ||
| 403 | "Size of thumbnails, in pixels. | 407 | "Size of thumbnails, in pixels. |
| 404 | This is the default size for both `image-dired-thumb-width' | 408 | This is the default size for both `image-dired-thumb-width' |
| 405 | and `image-dired-thumb-height'." | 409 | and `image-dired-thumb-height'." |
| @@ -569,7 +573,8 @@ Add text properties ORIGINAL-FILE-NAME and ASSOCIATED-DIRED-BUFFER." | |||
| 569 | (setq beg (point)) | 573 | (setq beg (point)) |
| 570 | (image-dired-insert-image file | 574 | (image-dired-insert-image file |
| 571 | ;; TODO: this should depend on the real file type | 575 | ;; TODO: this should depend on the real file type |
| 572 | (if (eq 'standard image-dired-thumbnail-storage) | 576 | (if (memq image-dired-thumbnail-storage |
| 577 | '(standard standard-large)) | ||
| 573 | 'png 'jpeg) | 578 | 'png 'jpeg) |
| 574 | image-dired-thumb-relief | 579 | image-dired-thumb-relief |
| 575 | image-dired-thumb-margin) | 580 | image-dired-thumb-margin) |
| @@ -591,13 +596,16 @@ MD5-hash of the image file's directory name and add that to make | |||
| 591 | the thumbnail file name unique. For per-directory storage, just | 596 | the thumbnail file name unique. For per-directory storage, just |
| 592 | add a subdirectory. For standard storage, produce the file name | 597 | add a subdirectory. For standard storage, produce the file name |
| 593 | according to the Thumbnail Managing Standard." | 598 | according to the Thumbnail Managing Standard." |
| 594 | (cond ((eq 'standard image-dired-thumbnail-storage) | 599 | (cond ((memq image-dired-thumbnail-storage '(standard standard-large)) |
| 595 | (let* ((xdg (getenv "XDG_CACHE_HOME")) | 600 | (let* ((xdg (getenv "XDG_CACHE_HOME")) |
| 596 | (dir (if (and xdg (file-name-absolute-p xdg)) | 601 | (dir (if (and xdg (file-name-absolute-p xdg)) |
| 597 | xdg "~/.cache"))) | 602 | xdg "~/.cache")) |
| 603 | (thumbdir (cl-case image-dired-thumbnail-storage | ||
| 604 | (standard "thumbnails/normal") | ||
| 605 | (standard-large "thumbnails/large")))) | ||
| 598 | (expand-file-name | 606 | (expand-file-name |
| 599 | (concat (md5 (concat "file://" (expand-file-name file))) ".png") | 607 | (concat (md5 (concat "file://" (expand-file-name file))) ".png") |
| 600 | (expand-file-name "thumbnails/normal" dir)))) | 608 | (expand-file-name thumbdir dir)))) |
| 601 | ((eq 'use-image-dired-dir image-dired-thumbnail-storage) | 609 | ((eq 'use-image-dired-dir image-dired-thumbnail-storage) |
| 602 | (let* ((f (expand-file-name file)) | 610 | (let* ((f (expand-file-name file)) |
| 603 | (md5-hash | 611 | (md5-hash |
| @@ -622,23 +630,29 @@ according to the Thumbnail Managing Standard." | |||
| 622 | (unless (executable-find (symbol-value executable)) | 630 | (unless (executable-find (symbol-value executable)) |
| 623 | (error "Executable %S not found" executable))) | 631 | (error "Executable %S not found" executable))) |
| 624 | 632 | ||
| 633 | (defun image-dired-thumb-size (dimension) | ||
| 634 | "Return thumb size depending on `image-dired-thumbnail-storage'. | ||
| 635 | DIMENSION should be either the symbol 'width or 'height." | ||
| 636 | (cond | ||
| 637 | ((eq 'standard image-dired-thumbnail-storage) 128) | ||
| 638 | ((eq 'standard-large image-dired-thumbnail-storage) 256) | ||
| 639 | (t (cl-ecase dimension | ||
| 640 | (width image-dired-thumb-width) | ||
| 641 | (height image-dired-thumb-height))))) | ||
| 642 | |||
| 625 | (defun image-dired-create-thumb (original-file thumbnail-file) | 643 | (defun image-dired-create-thumb (original-file thumbnail-file) |
| 626 | "For ORIGINAL-FILE, create thumbnail image named THUMBNAIL-FILE." | 644 | "For ORIGINAL-FILE, create thumbnail image named THUMBNAIL-FILE." |
| 627 | (image-dired--check-executable-exists | 645 | (image-dired--check-executable-exists |
| 628 | 'image-dired-cmd-create-thumbnail-program) | 646 | 'image-dired-cmd-create-thumbnail-program) |
| 629 | (let* ((width | 647 | (let* ((width (int-to-string (image-dired-thumb-size 'width))) |
| 630 | (int-to-string (or (and (eq image-dired-thumbnail-storage 'standard) 128) | 648 | (height (int-to-string (image-dired-thumb-size 'height))) |
| 631 | image-dired-thumb-width))) | ||
| 632 | (height | ||
| 633 | (int-to-string (or (and (eq image-dired-thumbnail-storage 'standard) 128) | ||
| 634 | image-dired-thumb-height))) | ||
| 635 | (modif-time (format "%.0f" (float-time (nth 5 (file-attributes | 649 | (modif-time (format "%.0f" (float-time (nth 5 (file-attributes |
| 636 | original-file))))) | 650 | original-file))))) |
| 637 | (thumbnail-nq8-file (replace-regexp-in-string ".png\\'" "-nq8.png" | 651 | (thumbnail-nq8-file (replace-regexp-in-string ".png\\'" "-nq8.png" |
| 638 | thumbnail-file)) | 652 | thumbnail-file)) |
| 639 | (command | 653 | (command |
| 640 | (format-spec | 654 | (format-spec |
| 641 | (if (eq 'standard image-dired-thumbnail-storage) | 655 | (if (memq image-dired-thumbnail-storage '(standard standard-large)) |
| 642 | image-dired-cmd-create-standard-thumbnail-command | 656 | image-dired-cmd-create-standard-thumbnail-command |
| 643 | image-dired-cmd-create-thumbnail-options) | 657 | image-dired-cmd-create-thumbnail-options) |
| 644 | (list | 658 | (list |
| @@ -1636,8 +1650,7 @@ Calculate how many thumbnails fit." | |||
| 1636 | (/ width | 1650 | (/ width |
| 1637 | (+ (* 2 image-dired-thumb-relief) | 1651 | (+ (* 2 image-dired-thumb-relief) |
| 1638 | (* 2 image-dired-thumb-margin) | 1652 | (* 2 image-dired-thumb-margin) |
| 1639 | (or (and (eq image-dired-thumbnail-storage 'standard) 128) | 1653 | (image-dired-thumb-size 'width) |
| 1640 | image-dired-thumb-width) | ||
| 1641 | char-width)))) | 1654 | char-width)))) |
| 1642 | (image-dired-line-up))) | 1655 | (image-dired-line-up))) |
| 1643 | 1656 | ||