GNU bug report logs - #57961
29.0.50; [PATCH] image-dired thumbnail generation fails for PDFs on macOS

Previous Next

Package: emacs;

Reported by: Daniel Martín <mardani29 <at> yahoo.es>

Date: Tue, 20 Sep 2022 20:54:01 UTC

Severity: normal

Tags: patch

Found in version 29.0.50

Fixed in version 29.1

Done: Stefan Kangas <stefankangas <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 57961 in the body.
You can then email your comments to 57961 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#57961; Package emacs. (Tue, 20 Sep 2022 20:54:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Daniel Martín <mardani29 <at> yahoo.es>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 20 Sep 2022 20:54:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Daniel Martín <mardani29 <at> yahoo.es>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.50; [PATCH] image-dired thumbnail generation fails for PDFs on
 macOS
Date: Tue, 20 Sep 2022 22:53:19 +0200
[Message part 1 (text/plain, inline)]
I tried the new PDF thumbnail generation feature in image-dired and I
got the following error in the macOS console, and the thumbnails are
blank:

CoreGraphics PDF has logged an error. Set environment variable
"CG_PDF_VERBOSE" to learn more

The reason seems to be that the thumbnails are actually JPG files, but
they are created with PDF extension, so the image loading code in the NS
port sees the extension and tries to search for a %PDF marker in the
file, which always fails.

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

Any ideas if the logic is correct and makes sense?  Thanks.

In GNU Emacs 29.0.50 (build 3, aarch64-apple-darwin21.6.0, NS
 appkit-2113.60 Version 12.6 (Build 21G115)) of 2022-09-20 built on
 Daniels-MacBook-Pro.local
Repository revision: 1231a601ebe1fd9fe454c504dbeb9267440242e7
Repository branch: master
Windowing system distributor 'Apple', version 10.3.2113
System Description:  macOS 12.6

Configured using:
 'configure CPPFLAGS=-I/opt/homebrew/opt/openjdk <at> 11/include'

Configured features:
ACL DBUS GLIB GNUTLS JSON LCMS2 LIBXML2 MODULES NOTIFY KQUEUE NS PDUMPER
PNG RSVG SQLITE3 THREADS TOOLKIT_SCROLL_BARS WEBP XIM ZLIB

Important settings:
  value of $LANG: en_ES.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Messages

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  buffer-read-only: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny rfc822
mml mml-sec password-cache epa derived epg rfc6068 epg-config gnus-util
text-property-search mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils time-date subr-x misearch multi-isearch
format-spec vc-git diff-mode easy-mmode vc-dispatcher image-file
image-converter dired-aux image-dired image-dired-tags
image-dired-external image-dired-util image-mode wallpaper xdg exif
cl-loaddefs cl-lib dired dired-loaddefs rmc iso-transl tooltip eldoc
paren electric uniquify ediff-hook vc-hooks lisp-float-type elisp-mode
mwheel term/ns-win ns-win ucs-normalize mule-util term/common-win
tool-bar dnd fontset image regexp-opt fringe tabulated-list replace
newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock
font-lock syntax font-core term/tty-colors frame minibuffer nadvice seq
simple cl-generic indonesian philippine cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese composite emoji-zwj charscript charprop case-table
epa-hook jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button
loaddefs faces cus-face macroexp files window text-properties overlay
sha1 md5 base64 format env code-pages mule custom widget keymap
hashtable-print-readable backquote threads dbusbind kqueue cocoa ns
lcms2 multi-tty make-network-process emacs)

Memory information:
((conses 16 82066 6542)
 (symbols 48 6208 0)
 (strings 32 19408 2168)
 (string-bytes 1 585126)
 (vectors 16 11857)
 (vector-slots 8 170638 10214)
 (floats 8 39 25)
 (intervals 56 5237 164)
 (buffers 1000 12))

[0001-Fix-a-bug-where-PDF-thumbnails-were-stored-with-PDF-.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#57961; Package emacs. (Wed, 21 Sep 2022 11:43:01 GMT) Full text and rfc822 format available.

Message #8 received at 57961 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Daniel Martín <mardani29 <at> yahoo.es>
Cc: 57961 <at> debbugs.gnu.org, Stefan Kangas <stefankangas <at> gmail.com>
Subject: Re: bug#57961: 29.0.50; [PATCH] image-dired thumbnail generation
 fails for PDFs on macOS
Date: Wed, 21 Sep 2022 13:42:14 +0200
Daniel Martín <mardani29 <at> yahoo.es> 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.
>
> Any ideas if the logic is correct and makes sense?  Thanks.

I think the patch makes sense.  Perhaps Stefan has some comments; added
to the CCs.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#57961; Package emacs. (Wed, 21 Sep 2022 13:10:01 GMT) Full text and rfc822 format available.

Message #11 received at 57961 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Daniel Martín <mardani29 <at> yahoo.es>, 57961 <at> debbugs.gnu.org
Subject: Re: 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 <at> 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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#57961; Package emacs. (Wed, 21 Sep 2022 13:59:02 GMT) Full text and rfc822 format available.

Message #14 received at 57961 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Daniel Martín <mardani29 <at> yahoo.es>, 57961 <at> debbugs.gnu.org
Subject: Re: bug#57961: 29.0.50; [PATCH] image-dired thumbnail generation
 fails for PDFs on macOS
Date: Wed, 21 Sep 2022 06:58:34 -0700
BTW, I just pushed some tests to master (commit 661be73b5e), so I please
update them too.

Thanks in advance.




bug marked as fixed in version 29.1, send any further explanations to 57961 <at> debbugs.gnu.org and Daniel Martín <mardani29 <at> yahoo.es> Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 28 Sep 2022 10:46:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#57961; Package emacs. (Wed, 28 Sep 2022 10:47:01 GMT) Full text and rfc822 format available.

Message #19 received at 57961 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Daniel Martín <mardani29 <at> yahoo.es>
Cc: 57961 <at> debbugs.gnu.org
Subject: Re: bug#57961: 29.0.50; [PATCH] image-dired thumbnail generation
 fails for PDFs on macOS
Date: Wed, 28 Sep 2022 06:45:49 -0400
close 57961 29.1
thanks

Stefan Kangas <stefankangas <at> gmail.com> writes:

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

I took a closer look at this, and I decided that while forcing the file
extension to ".jpg", we might as well take the opportunity to simplify
the naming of thumbnails.

So I did that in commit 6cffaa3b6d, and I'm therefore closing this bug report.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 26 Oct 2022 11:24:12 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 176 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.