Two Explorer thumbnail bugs

C

Csaba2000

I first noticed this nearly two years ago on my Win 2K Pro
system, and it's still here on my Win XP Pro system, so...

I have a program which rotates .jpg files by changing a
minimal number of bits in the file that specifies orientation (it's one
or two bytes if I remember correctly). This is fast. I wrap this in
a program which looks at the file (modification) date
(http://php.net/filemtime) and does a file touch (http://php.net/touch)
with the original date after changing the rotation). This part works
well.

The problem is that as soon as the file's date is reset to the original,
the thumbnail for it reverts back to the original (if you don't suspend
the process right before the touching, it will just seem like nothing
has changed) - it is an incorrect thumbnail. That's a bug.

This happens with or without thumbnail cacheing being on, and in both
folder styles: Tools / Folder Options / Show common tasks in folders
and also Use Windows classic folders.

There are two ways I know to "adjust" the thumbnails (fix the images).
Both of these are with thumbnail cacheing off (I've forgotten the details
of what happens when it's on, but I think it's worse). One is to close
the folder and reopen it. This is the cleanest in the sense that
everything is redone from scratch but it's pretty awful from a user
interface point of view.

The second is that if there is at least one image selected, you can, either
from the File menu or the context menu, do a Re&fresh Thumbnail.
This will clean up the thumbnail cache for that file. Or so it seems.
If you now press F5 then you will see those thumbnails that were
refreshed CYCLE through the images that were there before and
after the Refresh Thumbnail for that image. That's a bug.
For example, if you refresh one image once during the process of
rotation that gives a cycle of 2. If you refresh one image twice, that
gives a cycle of 3. If you refreshed one image once and another
image twice (since the last opening of the folder) it would take you
six F5 hits to cycle through all the combinations (the least common
multiple of 2 and 3).

If I have ahold of the IWebBrowser2 COM object (in VB/Script),
an element of CreateObject("Shell.Application).Windows, that
corresponds to the folder in question, then doing a Refresh2(3)
seems to correspond to hitting the F5 key (I didn't do exhaustive
testing of 0-2). However, in no case did the thumbnails reset to
the correct relection of the images. It is a nice idea to be able to
programmatically refresh Explorer's display of files - it would be
great if it worked.

Finally, I just want to stress that there was no thumbs.db during
this testing process since I turned off thumbnail cacheing. That
would seem to indicate that it's a Windows Explorer issue.

There you have it. For further enlightenment you could try to
reach me over email or (+1)212-400-7927, since my monitoring
of this group is probably short lived.
Csaba Gabor
 
R

Rehan

[...]
The problem is that as soon as the file's date is reset to the original,
the thumbnail for it reverts back to the original (if you don't suspend
the process right before the touching, it will just seem like nothing
has changed) - it is an incorrect thumbnail. That's a bug.

Very difficult to comment without knowing exact details of your program. But
it seems you need to enable ThumbsCache and manually update it when you
modify timestamps of the files. Modify your script/program to mark the
Thumbs.db to be "deleted" in the folder if a picture is changed in this
manner. After the script is finished doing its work over all pictures, it
can delete the cache. I am assuming that the deleting the cache is safe
enough operation.

Otherwise... post your script/source code for review.
 
C

Csaba2000

Very difficult to comment without knowing exact details of your program.

<?php
$path = "c:\\Photo\\Util\\Short name.jpg";
$oldTime = filemtime($path);
$cmd = "c:\\Photo\\util\\jpegtran.exe -rotate 90 \"$path\" \"$path\"";
system($cmd); // do the rotation
touch($path, $oldTime); // reset original time onto the file
?>
it seems you need to enable ThumbsCache and manually update it when you

NO! That makes it worse. If Thumbnail cacheing is on
(Tools / Folder Options / View), then the thumbnails
are retained even if I close the folder and then reopen it.
Part of the point that I was making was that this problem
is inherent to Windows Explorer. Having thumbnail
cacheing on adds complexity to the issue.
modify timestamps of the files. Modify your script/program to mark the
Thumbs.db to be "deleted" in the folder if a picture is changed in this
manner. After the script is finished doing its work over all pictures, it
can delete the cache. I am assuming that the deleting the cache is safe
enough operation.

I assume deletion of Thumbs.db is what you mean by manually updating.
It appears safe enough, but it does not help the situation. In particular,
upon deletion of thumbs.db the current thumbnail images are retained.
In this situation you need to both delete Thumbs.db AND exit the folder
before the updated thumbnail is shown. With either Thumbnail cacheing
on or off, clicking Re&fresh Thumbnail works (again, I have not been
able to get to this programmatically, which would be the cleaner solution).
Otherwise... post your script/source code for review.

This (command line - CLI) PHP code (above) is pretty basic, reflecting
exactly what I wrote originally.
1. Record the time of the old file
2. Give the file to an exe that will alter a byte or two
3. Reset the time on the modified (same size) file

If you want to put a pause in, insert between the last two lines of code
(if using PHP5):
$oWSH = new COM("WScript.Shell");
$oWSH->Popup("Pausing",4,"Thumbnail demo",48);

Can't post jpegtran.exe (since it's not mine to post). But if I recall
correctly
from investigating this excellent piece of freeware two years ago and
looking
into the JPEG format specs, rotation changes precious little in a JPG file -
just
a byte or two.

Csaba Gabor
 
R

Rehan

I will play with your issue and the script. I am thinking that it might be
related to the EXIF data of these JPGs... EXIF has its own thumbnail field
which is cached within the exif header. May be the jpegtran.exe program does
not update that filed and windows explorer is using it to update its own
cache. If so it would behave as you describe as the code might be like this:

if(exif_thumb_modify_date > file_date)
{
show exif_thumbnail
{
else
{
thumb = regenerate_thumbnail()
show thumb;
}


Whn you 'touch' the image file it would leave the exif thumb modify date to
be newer.

All a theory, but worth investigating ... :)
Do post an update if you find a resolution.

--
Rehan
www.rehanfx.org - get more effects and transitions for Windows Movie Maker





Csaba2000 said:
Very difficult to comment without knowing exact details of your program.
But

<?php
$path = "c:\\Photo\\Util\\Short name.jpg";
$oldTime = filemtime($path);
$cmd = "c:\\Photo\\util\\jpegtran.exe -rotate 90 \"$path\" \"$path\"";
system($cmd); // do the rotation
touch($path, $oldTime); // reset original time onto the file
?>
it seems you need to enable ThumbsCache and manually update it when you

NO! That makes it worse. If Thumbnail cacheing is on
(Tools / Folder Options / View), then the thumbnails
are retained even if I close the folder and then reopen it.
Part of the point that I was making was that this problem
is inherent to Windows Explorer. Having thumbnail
cacheing on adds complexity to the issue.
modify timestamps of the files. Modify your script/program to mark the
Thumbs.db to be "deleted" in the folder if a picture is changed in this
manner. After the script is finished doing its work over all pictures, it
can delete the cache. I am assuming that the deleting the cache is safe
enough operation.

I assume deletion of Thumbs.db is what you mean by manually updating.
It appears safe enough, but it does not help the situation. In
particular,
upon deletion of thumbs.db the current thumbnail images are retained.
In this situation you need to both delete Thumbs.db AND exit the folder
before the updated thumbnail is shown. With either Thumbnail cacheing
on or off, clicking Re&fresh Thumbnail works (again, I have not been
able to get to this programmatically, which would be the cleaner
solution).
Otherwise... post your script/source code for review.

This (command line - CLI) PHP code (above) is pretty basic, reflecting
exactly what I wrote originally.
1. Record the time of the old file
2. Give the file to an exe that will alter a byte or two
3. Reset the time on the modified (same size) file

If you want to put a pause in, insert between the last two lines of code
(if using PHP5):
$oWSH = new COM("WScript.Shell");
$oWSH->Popup("Pausing",4,"Thumbnail demo",48);

Can't post jpegtran.exe (since it's not mine to post). But if I recall
correctly
from investigating this excellent piece of freeware two years ago and
looking
into the JPEG format specs, rotation changes precious little in a JPG
file - just
a byte or two.

Csaba Gabor
 
C

Csaba2000

Your post was somewhat disconcerting to me, because it raises the
possibility
that my trusty jpegtran.exe is in error (the point being that it is a
reasonable
thing to investigate). And if I am correct in my recollection (I'd rather
be
incorrect here) that my program is only changing a byte or two, then it is
surely the case that any thumbnail in the EXIF data is incorrect on a 90
degree rotation. But it will be correct again upon a second 90 degree
rotation (in the sense that the dimensions will match up again).

Therefore, can you recommend a freely available JPEG validator tool
so I can do the proper checks on my side?

I've looked at the Thumbnails in Irfanview, but I haven't found anything
there to suggest whether it's original (exif) data that is being displayed
or computed data. If it's exif data, then my jpegtran.exe is accounting
for the rotation, but irfanview is a pretty robust program...

I'm not following your code. In particular, I'm confused about that
exif_thumb_modify_date. I looked at
http://www.fifi.org/doc/jhead/exif-e.html
and didn't find date/time associated with thumbnails but perhaps my
search was incorrect? There was an original image time and
a time last modified (it's unclear to me what inherent purpose that
serves since the file itself has a file modification date).

The possible dates that could be of importance here are the:
JDate: Date last modified (within the JPG file)
MDate: File mtime (last modification date of the jpg file) as maintained by
the file system
TDate: Explorer's last computation of thumbnail

Using these names (or whatever format you care for, just explain it)
would you restate your algorithm. I tend to agree with you that there is
a date comparison thing going on, but it may not be so simple as that
since explorer cycles though previous thumbnails (as opposed to just
having a most recent one).

Yes, if I get a resolution on this, especially user error (!), I'll post.

Csaba

Rehan said:
I will play with your issue and the script. I am thinking that it might be
related to the EXIF data of these JPGs... EXIF has its own thumbnail field
which is cached within the exif header. May be the jpegtran.exe program
does not update that filed and windows explorer is using it to update its
own cache. If so it would behave as you describe as the code might be like
this:

if(exif_thumb_modify_date > file_date)
{
show exif_thumbnail
{
else
{
thumb = regenerate_thumbnail()
show thumb;
}


Whn you 'touch' the image file it would leave the exif thumb modify date
to be newer.

All a theory, but worth investigating ... :)
Do post an update if you find a resolution.

--
Rehan
www.rehanfx.org - get more effects and transitions for Windows Movie Maker
 
R

Rehan

I quick test would be to use a jpeg which does not have exif attached. You
may like to use Windows Powertoy Resize Image which removes all exif.


--
Rehan
www.rehanfx.org - get more effects and transitions for Windows Movie Maker
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top