- (let (file-dir file-name
- resized-file resized-dir
- spec)
- (cond
- (size
- (setq file-dir (file-name-directory file)
- file-name (file-name-nondirectory file))
- (setq resized-file
- (expand-file-name
- file-name
- (setq resized-dir
- (expand-file-name
- size file-dir))))
- (unless (file-exists-p resized-file)
- (setq size (intern size))
- (if (setq spec (assq size www-page-size-specs))
- (progn
- (condition-case nil
- (unless (file-exists-p resized-dir)
- (make-directory resized-dir))
- (error nil))
- (call-process
- "convert" nil nil nil
- "-resize" (format "%dx%d>" (nth 1 spec)(nth 2 spec))
- file resized-file)
- )
- (setq resized-file file)))
- ;; (princ resized-file)
- (setq file resized-file)
- )
- (t
- ;; (princ file)
- ))
- (princ (format "Content-Type: %s"
- (with-temp-buffer
- (call-process
- "file"
- nil t t
- "-b" "--mime" file)
- (insert "\n")
- (let ((coding-system-for-read 'binary)
- (coding-system-for-write 'binary))
- (insert-file-contents-literally file))
- (buffer-string))))))
+ (when (file-exists-p file)
+ (let (file-dir file-name
+ resized-file resized-dir
+ spec width height
+ orig-width orig-height
+ size-opt)
+ (setq size (intern size))
+ (cond
+ ((and size
+ (setq spec (assq size www-page-size-specs))
+ (setq width (nth 1 spec))
+ (setq height (nth 2 spec)))
+ (setq file-dir (file-name-directory file)
+ file-name (file-name-nondirectory file))
+ (setq size-opt
+ (or (when (and pivot-mode
+ (> width height))
+ (with-temp-buffer
+ (call-process "identify" nil t nil file)
+ (goto-char (point-min))
+ (if (re-search-forward
+ "^[^ ]+ [^ ]+ \\([0-9]+\\)x\\([0-9]+\\) " nil t)
+ (setq orig-width (string-to-int
+ (match-string 1))
+ orig-height (string-to-int
+ (match-string 2)))))
+ (if (> orig-height orig-width)
+ 'p))
+ ""))
+ (setq resized-file
+ (format "%s_%s%s.%s"
+ (file-name-sans-extension file)
+ size size-opt
+ (file-name-extension file)))
+ (unless (file-exists-p resized-file)
+ (setq resized-file
+ (expand-file-name
+ file-name
+ (setq resized-dir
+ (expand-file-name
+ (format "%s%s" size size-opt)
+ file-dir))))
+ (unless (file-exists-p resized-file)
+ (condition-case nil
+ (unless (file-exists-p resized-dir)
+ (make-directory resized-dir))
+ (error nil))
+ (call-process
+ "convert" nil nil nil
+ "-resize"
+ (if (eq size-opt 'p)
+ (format "%dx%d>" height width)
+ (format "%dx%d>" width height))
+ file resized-file)))
+ ;; (princ resized-file)
+ (setq file resized-file)
+ )
+ (t
+ ;; (princ file)
+ ))
+ (princ (format "Content-Type: %s"
+ (with-temp-buffer
+ (call-process
+ "file"
+ nil t t
+ "-b" "--mime" file)
+ (insert "\n")
+ (let ((coding-system-for-read 'binary)
+ (coding-system-for-write 'binary))
+ (insert-file-contents-literally file))
+ (buffer-string)))))))