Function: image-dired-create-thumb-1
image-dired-create-thumb-1 is a byte-compiled function defined in
image-dired.el.gz.
Signature
(image-dired-create-thumb-1 ORIGINAL-FILE THUMBNAIL-FILE)
Documentation
For ORIGINAL-FILE, create thumbnail image named THUMBNAIL-FILE.
Source Code
;; Defined in /usr/src/emacs/lisp/image-dired.el.gz
(defun image-dired-create-thumb-1 (original-file thumbnail-file)
"For ORIGINAL-FILE, create thumbnail image named THUMBNAIL-FILE."
(image-dired--check-executable-exists
'image-dired-cmd-create-thumbnail-program)
(let* ((width (int-to-string (image-dired-thumb-size 'width)))
(height (int-to-string (image-dired-thumb-size 'height)))
(modif-time (format-time-string
"%s" (file-attribute-modification-time
(file-attributes original-file))))
(thumbnail-nq8-file (replace-regexp-in-string ".png\\'" "-nq8.png"
thumbnail-file))
(spec
(list
(cons ?w width)
(cons ?h height)
(cons ?m modif-time)
(cons ?f original-file)
(cons ?q thumbnail-nq8-file)
(cons ?t thumbnail-file)))
(thumbnail-dir (file-name-directory thumbnail-file))
process)
(when (not (file-exists-p thumbnail-dir))
(message "Creating thumbnail directory")
(with-file-modes #o700
(make-directory thumbnail-dir t)))
;; Thumbnail file creation processes begin here and are marshaled
;; in a queue by `image-dired-create-thumb'.
(setq process
(apply #'start-process "image-dired-create-thumbnail" nil
image-dired-cmd-create-thumbnail-program
(mapcar
(lambda (arg) (format-spec arg spec))
(if (memq image-dired-thumbnail-storage
'(standard standard-large))
image-dired-cmd-create-standard-thumbnail-options
image-dired-cmd-create-thumbnail-options))))
(setf (process-sentinel process)
(lambda (process status)
;; Trigger next in queue once a thumbnail has been created
(cl-decf image-dired-queue-active-jobs)
(image-dired-thumb-queue-run)
(if (not (and (eq (process-status process) 'exit)
(zerop (process-exit-status process))))
(message "Thumb could not be created for %s: %s"
(abbreviate-file-name original-file)
(string-replace "\n" "" status))
(set-file-modes thumbnail-file #o600)
(clear-image-cache thumbnail-file)
;; PNG thumbnail has been created since we are
;; following the XDG thumbnail spec, so try to optimize
(when (memq image-dired-thumbnail-storage
'(standard standard-large))
(cond
((and image-dired-cmd-pngnq-program
(executable-find image-dired-cmd-pngnq-program))
(image-dired-pngnq-thumb spec))
((and image-dired-cmd-pngcrush-program
(executable-find image-dired-cmd-pngcrush-program))
(image-dired-pngcrush-thumb spec))
((and image-dired-cmd-optipng-program
(executable-find image-dired-cmd-optipng-program))
(image-dired-optipng-thumb spec)))))))
process))