Bug 220496 - Preview of pictures when content type does not match extension
Summary: Preview of pictures when content type does not match extension
Status: CONFIRMED
Alias: None
Product: kio-extras
Classification: Frameworks and Libraries
Component: Thumbnails and previews (show other bugs)
Version: 19.08.1
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: David Faure
URL:
Keywords:
: 316804 325367 (view as bug list)
Depends on:
Blocks:
 
Reported: 2009-12-29 05:35 UTC by Bruno Léon
Modified: 2021-08-01 11:22 UTC (History)
13 users (show)

See Also:
Latest Commit:
Version Fixed In: 19.04.0


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bruno Léon 2009-12-29 05:35:32 UTC
Version:            (using KDE 4.3.4)
OS:                Linux
Installed from:    Ubuntu Packages

I have a set of pictures where extension is jpeg, but I found out that content type is actually png.

With such file, kde does not build the preview image you can normally see in konqueror details view with preview activated obviously. Renaming to .png fixes the problem.

I know those file should have the extension .png, but still I think KDE should not rely on file extension to create the preview or not, which it does if my understanding of the issue is good.
Comment 1 disabled account 2011-05-27 20:52:14 UTC
Reassigned to dolphin.
Comment 2 Jekyll Wu 2011-12-14 21:18:12 UTC
This is probably a Qt bug. See bug 182361 for more information.
Comment 3 Jekyll Wu 2011-12-30 08:02:19 UTC
*** Bug 247964 has been marked as a duplicate of this bug. ***
Comment 4 Jeroen van Meeuwen (Kolab Systems) 2012-08-24 16:19:58 UTC
Resetting assignee to default as per bug #305719
Comment 5 Jekyll Wu 2013-03-16 02:07:10 UTC
*** Bug 316804 has been marked as a duplicate of this bug. ***
Comment 6 Frank Reininghaus 2013-03-16 09:13:22 UTC
IMHO, it makes no sense that every application (Gwenview, Dolphin, the file dialog, Folder View, etc.) finds its own workaround for this issue. I'm not exactly sure what the root cause is, but KIO::PreviewJob or the thumbnailing code in kde-runtime look like places where this could be fixed in a way such that every KDE application benefits from it.
Comment 7 Mircea Kitsune 2013-03-16 10:14:14 UTC
Confirmed. Although in KDE 4.10.0 this was fixed for Gwenview (and now it's able to open files with swapped extensions) it wasn't fixed for the thumbnail generator too like I imagined it automatically would.
Comment 8 Christoph Feck 2013-09-27 16:25:00 UTC
*** Bug 325367 has been marked as a duplicate of this bug. ***
Comment 9 miklos 2013-09-27 17:23:37 UTC
I can't believe this trivial-looking bug survived 4 years and 7 KDE releases.
Comment 10 Frank Reininghaus 2013-09-27 17:35:23 UTC
(In reply to comment #9)
> I can't believe this trivial-looking bug survived 4 years and 7 KDE releases.

Unfortunately, the number of people who invest their spare time into triaging and fixing KDE bugs is far too low to cope with the huge number of bug reports.

We would very much appreciate your help - if you believe that this one is simple to fix, please dig into the source and submit a patch to

https://git.reviewboard.kde.org/

Thanks for your help!
Comment 11 miklos 2016-06-12 14:00:30 UTC
Wow, it survived another 3 years!
Comment 12 Mircea Kitsune 2016-06-12 14:10:44 UTC
Confirming this still exists with Plasma 5.6.4, Dolphin 16.04.1 (latest openSUSE Tumbleweed packages). As much as I understand the limited workforce of free and open-source software, things like this going unfixed for years are what saddens and worries me about KDE.
Comment 13 miklos 2018-03-31 13:30:45 UTC
Now I found this again, and I had some time to debug it.

The file metadata is gathered by FileMetaDataWidget of baloo-widgets, which launches an external program (baloo_filemetadata_temp_extractor) to parse the file and return its properties, so the file description in the tooltip and the information panel is always correct.

The preview is generated with KIO::PreviewJob(), which gets the mime type of the file from its name: kio/src/widgets/previewjob.cpp:304 calls kio/src/core/kfileitem.cpp:732, where QMimeDatabase is asked for the mime type based on the file name. This is wrong when the file suffix is wrong, and apparently there is a different preview generator for jpeg and png.

I see three possible solutions:
- QMimeDatabase supports parsing the file to find out its type
- do not filter for mime type in PreviewJob, try all preview generators and accept the first success (the preview generators need to be ordered carefully to minimize the chance of false positive)
- use the file properties gathered by baloo-widgets when requesting the preview (this needs new API in KIO::PreviewJob, and I'm not sure if KIO is allowed to depend on Baloo)

I'm leaning toward option 2. It works fine in Okular for example.
Comment 14 Nate Graham 2018-04-13 22:08:10 UTC
Thanks for the investigation, Miklos! Would you like to submit a patch? I can help you out, and we have extensive documentation on this process:

- https://community.kde.org/Get_Involved/development
- https://community.kde.org/Infrastructure/Phabricator
Comment 15 miklos 2018-06-03 19:59:58 UTC
I finally had the time to dig into the rabbit hole and fix all the stupid code trying to detect the file type based on the file name suffix. These patches should fix the previews in Dolphin:
https://codereview.qt-project.org/#/c/231308/
https://phabricator.kde.org/D13314
https://phabricator.kde.org/D13315
https://phabricator.kde.org/D13316
Comment 16 Mircea Kitsune 2018-06-03 20:31:17 UTC
(In reply to miklos from comment #15)

It's amazing to finally see this solved after so long. Thank you! I hope the solution sticks this time and it doesn't break again in the future... ideally you can add code comments as well to make sure future developers know. Can't wait to see this fix in the next system updates :)
Comment 17 Elvis Angelaccio 2018-07-08 13:52:13 UTC
(In reply to miklos from comment #13)
> Now I found this again, and I had some time to debug it.
> 
> The file metadata is gathered by FileMetaDataWidget of baloo-widgets, which
> launches an external program (baloo_filemetadata_temp_extractor) to parse
> the file and return its properties, so the file description in the tooltip
> and the information panel is always correct.
> 
> The preview is generated with KIO::PreviewJob(), which gets the mime type of
> the file from its name: kio/src/widgets/previewjob.cpp:304 calls
> kio/src/core/kfileitem.cpp:732, where QMimeDatabase is asked for the mime
> type based on the file name. This is wrong when the file suffix is wrong,
> and apparently there is a different preview generator for jpeg and png.
> 
> I see three possible solutions:
> - QMimeDatabase supports parsing the file to find out its type

Just for the record, QMimeDatabase already has this feature.
Comment 18 Albert Astals Cid 2019-01-16 23:53:56 UTC
Git commit 0be80392f01e0ec01174990c430dcd8f1ed35d9e by Albert Astals Cid, on behalf of Miklós Máté.
Committed on 16/01/2019 at 23:53.
Pushed by aacid into branch 'master'.

image thumbnailer: instruct Qt to look at the file contents when detecting its format

This enables thumbnails in Dolphin for a png file named image.jpg for example.

M  +5    -2    thumbnail/imagecreator.cpp

https://commits.kde.org/kio-extras/0be80392f01e0ec01174990c430dcd8f1ed35d9e
Comment 19 Nate Graham 2019-01-19 16:00:35 UTC
Git commit 880a09adae2abbf18f92c008fd4c109876a96581 by Nate Graham, on behalf of Miklós Máté.
Committed on 19/01/2019 at 16:00.
Pushed by ngraham into branch 'master'.

manually set format in jpeg thumbnail creator

Summary:
Otherwise the QImageReader sets the format based on the file name suffix, which might be misleading, e.g. a jpeg file named image.png.

Reviewers: dfaure, elvisangelaccio, #frameworks

Reviewed By: dfaure, elvisangelaccio

Subscribers: kde-frameworks-devel, kfm-devel, ngraham

Tags: #dolphin, #frameworks

Differential Revision: https://phabricator.kde.org/D13316

M  +1    -1    thumbnail/jpegcreator.cpp

https://commits.kde.org/kio-extras/880a09adae2abbf18f92c008fd4c109876a96581
Comment 20 Patrick Silva 2019-02-15 20:43:52 UTC
does dolphin 18.12.2 include this fix?
png files with jpg extension are still without thumbnail here.

SOFTWARE/OS VERSIONS
dolphin 18.12.2
Operating System: Arch Linux 
KDE Plasma Version: 5.15.0
KDE Frameworks Version: 5.55.0
Qt Version: 5.12.1
Comment 21 Nate Graham 2019-02-15 20:45:01 UTC
No, updated the "version fixed in" field appropriately.
Comment 22 Bruno Léon 2019-02-16 07:45:49 UTC
Thanks for your work !
Comment 23 Patrick Silva 2019-03-30 17:17:33 UTC
It's not working with Dolphin 18.04 beta. I changed the extension of a screenshot taken with spectacle from .png to .jpg and Dolphin does not show the thumbnail of the screenshot.

Operating System: Arch Linux 
KDE Plasma Version: 5.15.3
KDE Frameworks Version: 5.56.0
Qt Version: 5.13.0
Comment 24 Patrick Silva 2019-03-30 17:18:29 UTC
ops, I meant Dolphin 19.04 beta.
Comment 25 Christoph Feck 2019-04-19 08:52:59 UTC
I can confirm comment #23. Only the reverse case works (renaming .jpeg to .png still shows the thumbnail).
Comment 26 Nate Graham 2019-04-19 14:32:51 UTC
That's odd. Thanks folks.
Comment 27 Ilya Bizyaev 2021-08-01 11:22:16 UTC
Still have this bug

Operating System: openSUSE Leap 15.3
KDE Plasma Version: 5.22.4
KDE Frameworks Version: 5.84.0
Qt Version: 5.15.2