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

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

bug#57961: 29.0.50; [PATCH] image-dired thumbnail generation fails for P


From: Stefan Kangas
Subject: bug#57961: 29.0.50; [PATCH] image-dired thumbnail generation fails for PDFs on macOS
Date: Wed, 21 Sep 2022 06:09:31 -0700

Daniel Martín via "Bug reports for GNU Emacs, the Swiss army knife of
text editors" <bug-gnu-emacs@gnu.org> writes:

> I've created this patch so that PDF thumbnails get the correct JPG or
> PNG extension.  That fixes the problem on macOS, at least.

Thanks for your testing and the patch!  Some comments below:

> diff --git a/lisp/image/image-dired-util.el b/lisp/image/image-dired-util.el
> index dcf0b22cfe..89513f9441 100644
> --- a/lisp/image/image-dired-util.el
> +++ b/lisp/image/image-dired-util.el
> @@ -57,6 +57,19 @@ image-dired-dir
>        (message "Thumbnail directory created: %s" image-dired-dir))
>      image-dired-dir))
>
> +(defun image-dired-file-name-extension (file)
> +  "Return the filename extension for thumbnail FILE.
> +Return the value of `file-name-extension', but for PDF files
> +return PNG or JPG, depending on the thumbnail storage
> +configuration."
> +  (let ((extension (file-name-extension file)))
> +    (cond ((string-equal extension "pdf")
> +           (cond ((memq image-dired-thumbnail-storage
> +                        image-dired--thumbnail-standard-sizes)
> +                  "png")
> +                 (t "jpg")))
> +          (t extension))))
> +

I don't think we need this when

    (memq image-dired-thumbnail-storage
          image-dired--thumbnail-standard-sizes)

because the files are then already saved to, e.g.:

    ~/.cache/thumbnails/normal/790f6914e3e396bf1b63f20769bd531d.png

>  (defun image-dired-thumb-name (file)
>    "Return absolute file name for thumbnail FILE.
>  Depending on the value of `image-dired-thumbnail-storage', the
> @@ -91,13 +104,13 @@ image-dired-thumb-name
>                     (file-name-as-directory (expand-file-name 
> (image-dired-dir)))
>                     (file-name-base f)
>                     (if hash (concat "_" hash) "")
> -                   (file-name-extension f))))
> +                   (image-dired-file-name-extension f))))

Given that we already hard-code the use of JPEG, perhaps we should just
hard-code ".jpg" here too?

Of course, that will break when users start messing with
`image-dired-cmd-create-thumbnail-options' but on the other hand they
are then on their own in any case.

>          ((eq 'per-directory image-dired-thumbnail-storage)
>           (let ((f (expand-file-name file)))
>             (format "%s.image-dired/%s.thumb.%s"
>                     (file-name-directory f)
>                     (file-name-base f)
> -                   (file-name-extension f))))))
> +                   (image-dired-file-name-extension f))))))

Same here.





reply via email to

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