gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

tumme.el 0.1


From: Mathias Dahl
Subject: tumme.el 0.1
Date: 16 Apr 2005 16:49:48 +0200
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.3

For those who may find this useful:

;;; tumme.el --- use dired to browse your images as thumbnails

;; Copyright (C) 2005 Mathias Dahl

;; Version: 0.1
;; Keywords: images, thumbnails, dired
;; Author: Mathias Dahl <address@hidden>
;; Maintainer: Mathias Dahl
;; URL: http://www.emacswiki.org/cgi-bin/wiki/Tumme

;; This file is not part of GNU Emacs.

;; This is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;;
;; This is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
;; License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:

;;  About the name: tumme means thumb in Swedish. Google did not give
;; me any hits for "tumme.el" so I thought it would be safe to use.
;;
;;  I needed a program to browse, organize and tag my pictures. I
;; got tired of the old gallery program I used as it did not allow
;; multi-file operations easily. Also, it put things out of my
;; control. Programs that did allow multi-file operations did not do
;; what I wanted it to.
;;
;;  So, I got the idea to use the wonderful functionality of emacs and
;; `dired' to do it. It would allow me to do almost anything I wanted,
;; which is basically just to browse all my pictures in an easy way,
;; letting me manipulate and tag them. `dired' already provide all the
;; file handling and navigation facilities; I only needed to add some
;; functions to display the images.
;;
;;  I briefly tried out thumbs.el, and although it seemed more
;; powerful than this package, it did not work the way I wanted to. It
;; was too slow to created thumbnails of all files in a directory (I
;; currently keep all my 2000+ images in the same directory) and
;; browsing the thumbnail buffer was slow too. tumme.el will not
;; create thumbnails until they are needed and the browsing is done
;; quickly and easily in dired.
;;
;;  `tumme' stores the thumbnail files in `tumme-dir' using the file
;; name format ORIGNAME.thumb.ORIGEXT. For example
;; ~/.tumme/myimage01.thumb.jpg.

;;; Feedback

;; Feedback is welcome, especially now when this is so fresh.

;;; Prerequisites:

;; * The convert program from the ImageMagick package

;;; Usage:

;; First, do M-x tumme-dired-folder RET. This will setup a useful
;; window- and buffer-configuration for you.
;;
;; The following keybindings works quite well, try them out and you
;; will get a feel for how the package works:
;;
;; (define-key dired-mode-map (kbd "C-S-n") 'tumme-next-line-and-display)
;; (define-key dired-mode-map (kbd "C-S-p") 'tumme-previous-line-and-display)
;; (define-key dired-mode-map (kbd "C-S-<return>") 'tumme-display-thumbs)
;;

;;; History:

;; Version 0.1, 2005-04-16
;; * First release, only browsing support for now.

;;; Bugs:

;; I'm not sure if I really consider this a bug, but in order to work
;; well, `tumme' require that all your images have unique names. The
;; reason is the way the thumbnail file name is generated. I will
;; probably not fix this problem as my images all have unique names.

;;; Todo:

;; - Add tagging capabilities. My plan is to use a simple text file as
;; a database and just add the tag information semi-colon separated
;; and appended to the file name. That would allow using things like
;; `occur', `flush-lines' and `keep-lines'.
;;
;; - Commands to open the images in full size, either in an emacs
;; buffer or external program, or both.
;;
;; - Find some way of toggling on and off really nice keybindings (for
;; example, using C-n or <down> instead of C-S-n) to the interactive
;; functions.
;;
;; - Functionality to display the varius tags next to the picture.
;;
;; - Command to refresh thumbnail images. For now, you have to delete
;; the old files manually.
;;
;; - Commands to create simple HTML-albums, where the images will be
;; browsable per tag, date file name etc.
;;

;;; Code:

(defgroup tumme nil
  "Use dired to browse your images as thumbnails"
  :prefix "tumme-"
  :group 'files)

(defcustom tumme-dir "~/.tumme/"
  "*Directory where thumbnail images for are stored."
  :type 'string
  :group 'tumme)

(defcustom tumme-file-name-display-format "\n%s"
  "*Format used to display the file name to the right of the
picture. `%s' is the file name. If you want extra space between each
thumbnail, add extra newlines at the end of the format. If you want to
have the file name next to the thumbnail, use no newline at all."
  :type 'string
  :group 'tumme)

(defcustom tumme-thumb-size 100
  "Size of thumbnails, in pixels"
  :type 'integer
  :group 'tumme)

(defun tumme-ins-img (file)
  "For now, just a wrapper for insert image file."
  (insert-image-file file))

(defun tumme-thumb-name (file)
  "Return thumbnail file name for FILE"
  (format "%s%s.thumb.%s"
          (expand-file-name tumme-dir)
          (file-name-sans-extension (file-name-nondirectory file))
          (file-name-extension file)))

(defun tumme-create-thumb (file)
  "Using the convert program, create thumbnail image for FILE and
place it in `tumme-dir'"
  (let* ((size (int-to-string tumme-thumb-size))
         (command
          (format
           "convert -size %sx%s %s -resize %sx%s +profile \"*\" %s"
           size
           size
           file
           size
           size
           (tumme-thumb-name file))))
    (if (file-exists-p tumme-dir)
        (if (not (file-directory-p tumme-dir))
            (error "%s exists but is not a directory!" tumme-dir))
      (make-directory tumme-dir))
    (shell-command command nil)))

(defun tumme-next-line-and-display ()
  "Move to next dired line and display thumbnail image"
  (interactive)
  (dired-next-line 1)
  (tumme-display-thumbs t))

(defun tumme-previous-line-and-display ()
  "Move to previous dired line and display thumbnail image"
  (interactive)
  (dired-previous-line 1)
  (tumme-display-thumbs t))

(defun tumme-dired-folder ()
  "Convenience command that:

 - Opens dired in folder specified by the user
 - Splits the window horizontally
 - Set truncate-lines to t
"
  (interactive)
  (let ((buf (get-buffer-create "*tumme*")))
    (call-interactively 'dired)
    (split-window-horizontally)
    (setq truncate-lines t)
    (save-excursion
      (other-window 1)
      (switch-to-buffer buf)
      (other-window -1))))

(defun tumme-display-thumbs (arg)
  "Display thumbnail images of all marked files in buffer *tumme*. If
a thumbnail image does not exist for a file, it is created on the
fly. With prefix 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 *tumme* buffer in
the right window.
"
  (interactive "P")
  (let ((buf (get-buffer-create "*tumme*"))
        curr-file thumb-name files)
    (if arg
        (setq files (list (dired-filename-at-point)))
      (setq files (dired-get-marked-files)))
    (save-excursion
      (set-buffer buf)
      (erase-buffer)
      (mapcar
       (lambda (x)
         (setq curr-file x)
         (setq thumb-name (tumme-thumb-name curr-file))
         (if (not (file-exists-p thumb-name))
             (if (not (= 0 (tumme-create-thumb curr-file)))
                 (error "Thumb could not be created")))
         (tumme-ins-img thumb-name)
         (end-of-line)
         (insert (format tumme-file-name-display-format
                         (file-name-nondirectory curr-file)))
         (goto-char (point-max))
         (insert "\n"))
       files))))

(provide 'tumme)

;;; tumme.el ends here


reply via email to

[Prev in Thread] Current Thread [Next in Thread]