11

Sometimes I crop PDFs in order to have a one-page reading instead of a scanned two pages. However, nautilus keeps an old thumbnail showing the former front page.

I know that I can delete the hidden thumbnails folder, but I'd like to know how can I regenerate only one specific thumbnail. F5 doesn't help.

1
  • 1
    I used the trick to go into command line and do a mv file newfile, wait a bit, and mv newfile file. Used to work.
    – Rmano
    May 1, 2014 at 5:25

5 Answers 5

10

According to the freedesktop documentation Thumbnail Managing Standard . You can force nautilus to recreate the thumbnail if the mtime (modification time) in the thumbnail is lower than the mtime in the original file.

  1. Detect Modifications

One important thing is to assure that the thumbnail image displays the same information than the original, only in a downscaled version. To make this possible we use the modification time stored in the required 'Thumb::MTime' key and check if it's equal the current modification time of the original. If not we must recreate the thumbnail.

Example 2. Algorithm to check for modification.

if (file.mtime != thumb.MTime) { recreate_thumbnail (); }

It is not sufficient to do a file.mtime > thumb.MTime check. If the user moves >another file over the original, where the mtime changes but is in fact lower than >the thumbnail stored mtime, we won't recognize this modification.

In order to achieve this... you can try with a little Nautilus-Script to set the mtime in the original file to the current time with the touch command.

1) Creating the script. Open a Terminal window Ctrl+Alt+T and type:

For Ubuntu 12.04 & 12.10

  • nano ~/.gnome2/nautilus-scripts/Regenerate-Thumbnail

For Ubuntu 13.04 & above

  • nano ~/.local/share/nautilus/scripts/Regenerate-Thumbnail

2) The content of the script.

#!/bin/bash

BAKIFS=$IFS
IFS=$'\n'

for FILE in $NAUTILUS_SCRIPT_SELECTED_FILE_PATHS; do
      touch -m "$FILE"
done

IFS=$BAKIFS

To save the changes in nano.. Ctrl+O,Enter then Ctrl+X.

3) To make the script executable.

For Ubuntu 12.04 & 12.10

  • chmod +x ~/.gnome2/nautilus-scripts/Regenerate-Thumbnail

For Ubuntu 13.04 & above

  • chmod +x ~/.local/share/nautilus/scripts/Regenerate-Thumbnail

4) To test the script you can open nautilus, select a file(s), right click and go to Scripts > Regenerate-Thumbnail.

enter image description here

enter image description here

enter image description here

enter image description here

Hope this helps.

0
4

I know this is an old question, but... sometime the thumbnails get stuck and no trick with touch -m or mv makes it regenerate.

Write this simple script (thanks to this answer), let's call it find-gnome-thumbnail:

#! /bin/bash 
#
fn=$(echo -n "$1" | md5sum | awk '{print $1}')
find $HOME/.cache/ -name "$fn*" 2> /dev/null

and feed it with the canonical name of the file of which you want to determine the thumbnail location. The better way to do this is to select the file in nautilus, do ctrlC, and in a terminal write find-gnome-thumbnail ' (with the space and the opening single quote) and after that shiftctrlV; add the closing quote and you'll have something like this:

 % ./find-gnome-thumbnail 'file:///home/romano/tmp/0101_IM_3026506.pdf' 
/home/romano/.cache/thumbnails/large/d090cf90d2ac3f8127f62043f06b66df.png

Now you can delete the offending thumbnail and it will be regenerated (press F5 if it does not happen alone). The copy-paste trick take care of strange chars conversions:

 % ./find-gnome-thumbnail 'file:///home/romano/tmp/lalla%20(copy).pdf'
 /home/romano/.cache/thumbnails/large/28864dd40fab6d4982e1b103365574da.png

Sometime the script fails if you rename the file with mv, I do not know why --- but it's ok most of the times. Also deleting the thumbnail manually does not regenerate it immediately --- again, I am at a loss here.

2

Simplified answer (based on @Roman Raguet)

  1. Open Terminal
  2. Go to the folder where your files are, for example, /home/me/myimages
  3. Execute touch -m

    • Either to a single file, for example, touch -m myfile.jpg
    • Or to all files, touch -m *

Now the thumbnails should be regenerated in your nautilus.

2

I have a script that I use (author unknown) called Auto Thumbnailer which works fine for this. I got it in a package of scripts that I obtained here.

and installed it in /.local/share/nautilus/scripts

Edit: Here's the script I used (extracted from the deb package).

#!/bin/sh

#Dialog box to choose thumb's size
SIZE=`zenity --list --title="Choose the thumbnail's size" --radiolist --column="Check" --column="Size" "" "100X100" "" "320x240" "" "640x480" "" "800x600" "" "1024x768"`
if [ "${SIZE}" == "" ]; then    
zenity --error --text="Size not defined by user.
Please choose a size to use. "
exit 1
fi

# How many files to make the progress bar
PROGRESS=0
NUMBER_OF_FILES=`find -iname "*.jpg" -maxdepth 1 | wc -l`
let "INCREMENT=100/$NUMBER_OF_FILES"

mkdir -p thumbnails

# Creating thumbnails. Specific work on picture should be add there as convert's option
(for i in *.jpg *.JPG; do
echo "$PROGRESS";
echo "# Resizing $i";
convert -resize "${SIZE}"  -bordercolor black -quality 90 "${i}" thumbnails/"${i}"
let "PROGRESS+=$INCREMENT"
done
) | zenity  --progress --title "$Creating thumbnails..." --percentage=0

#process png
# How many files to make the progress bar
PROGRESS=0
NUMBER_OF_FILES=`find -iname "*.png" -maxdepth 1 | wc -l`
let "INCREMENT=100/$NUMBER_OF_FILES"

mkdir -p thumbnails

# Creating thumbnails. Specific work on picture should be add there as convert's option
(for i in *.png *.PNG; do
echo "$PROGRESS";
echo "# Resizing $i";
convert -resize "${SIZE}"  -bordercolor black -quality 90 "${i}"         thumbnails/"${i}"
let "PROGRESS+=$INCREMENT"
done
) | zenity  --progress --title "$Creating thumbnails..." --percentage=0

Note that this script was 5 years old when I found it and could certainly use some updating today.

Edit Jan 20 2021: This failed miserably on Ubuntu 18.04. I was able to refresh failed thumbnails by deleting the ~/.cache/thumbnails/fail directory

0

In my case touch -m * and touch * only re-generate all but still not re-generate for the problematic images. md5sum of that images also not found in ~/.cache/.

Then I do experiment by copy all "ok" images to other directory to backup, leaving only 3 problematic images in that folder, and use strace to debug what path it open, does it open ~/.cache/thumbnails as other answer mentioned? (The log below is my second attempt with 1 problematic image):

xb@dnxb:~/.cache/thumbnails/normal$ strace -f -e open,openat nautilus '<My Directory>' |& grep -ni thumbnail
...
1428:[pid 30799] openat(AT_FDCWD, "/home/xiaobai/.cache/thumbnails/fail/gnome-thumbnail-factory/d3b419c7166b51189307c0c0c9e1e559.png", O_RDONLY) = 36
^C

I observed that 3 images inside ~/.cache/thumbnails/fail/ which has different md5sum, no wonder md5sum trick is not working.

Then I try eog <original image path> ("Eye of GNOME" program) to think and surprising me, thumbnails get re-generate in nautilus when try strace second time with this log:

xb@dnxb:~/.cache/thumbnails/normal$ strace -f -e open,openat nautilus '<My Directory>' |& gi thumbnail
...
1422:[pid 30904] openat(AT_FDCWD, "/home/xiaobai/.cache/thumbnails/normal/d3b419c7166b51189307c0c0c9e1e559.png", O_RDONLY) = 36
...
1428:[pid 30909] openat(AT_FDCWD, "/home/xiaobai/.cache/thumbnails/normal/d3b419c7166b51189307c0c0c9e1e559.png", O_RDONLY) = 35
...
^C
xb@dnxb:~/.cache/thumbnails/normal$ 

The thumbnails with the same md5 filename moved into ~/.cache/thumbnails/normal/ from ~/.cache/thumbnails/fail/

So run eog * command from terminal can fix this too (Note: I did touch -m * and touch * before, and strace nautilus to view the image outcome). And for OP question, can use eog <image path>.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .