Function: image-dired-pngcrush-thumb

image-dired-pngcrush-thumb is a byte-compiled function defined in image-dired-external.el.gz.

Signature

(image-dired-pngcrush-thumb SPEC)

Documentation

Optimize thumbnail described by format SPEC with command pngcrush.

Source Code

;; Defined in /usr/src/emacs/lisp/image/image-dired-external.el.gz
(defun image-dired-pngcrush-thumb (spec)
  "Optimize thumbnail described by format SPEC with command `pngcrush'."
  ;; If pngnq wasn't run, then the THUMB-nq8.png file does not exist.
  ;; pngcrush needs an infile and outfile, so we just copy THUMB to
  ;; THUMB-nq8.png and use the latter as a temp file.
  (when (not image-dired-cmd-pngnq-program)
    (let ((temp (cdr (assq ?q spec)))
          (thumb (cdr (assq ?t spec))))
      (copy-file thumb temp)))
  (let* ((args (mapcar
                (lambda (arg)
                  (format-spec arg spec))
                image-dired-cmd-pngcrush-options))
         (snt (lambda (process status)
                (unless (or (and (processp process)
                                 (eq (process-status process) 'exit)
                                 (zerop (process-exit-status process)))
                            (zerop status))
                  (if (processp process)
                      (message "command %S %s" (process-command process)
                               (string-replace "\n" "" status))
                    (message "command %S failed with status %s"
                             process status)))
                (when (or (not (processp process))
                          (memq (process-status process) '(exit signal)))
                  (let ((temp (cdr (assq ?q spec))))
                    (delete-file temp)))))
         (proc
          (if (eq system-type 'windows-nt)
              ;; See above for the reasons we don't use 'start-process'
              ;; on MS-Windows.
              (apply #'call-process
                     image-dired-cmd-pngcrush-program nil nil nil args)
            (apply #'start-process "image-dired-pngcrush" nil
                   image-dired-cmd-pngcrush-program args))))
    (if (processp proc)
        (setf (process-sentinel proc) snt)
      (funcall snt image-dired-cmd-pngcrush-program proc))
    proc))