Item4309: Updatet Images are not re-rendered by ImagePlugin

pencil
Priority: Normal
Current State: Closed
Released In: n/a
Target Release: n/a
Applies To: Extension
Component: ImagePlugin
Branches: trunk
Reported By: TWiki:Main.CedricWeber
Waiting For:
Last Change By: MichaelDaum
ImagePlugin does not update new images attached to a topic.

E.g. if a new version of screenshot is uploaded by a user, the resized image within the topic (created by ImagePlugin) remains with the old image.

-- TWiki:Main/CedricWeber - 27 Jun 2007

Sounds like ImagePlugin could do with an attachhandler.

-- TWiki:Main.SteffenPoulsen - 16 Sep 2007

I've just come across this bug. I've written a patch. Note that the patch uses TWiki::Func::getPubDir(), which is deprecated. It's currently a bit of a hack: I'm not sure what extensions ImagePlugin allows, so I just put the popular ones in there for the regex. As it does an unlink: use at your own risk smile

sub afterAttachmentSaveHandler {
    # do not uncomment, use $_[0], $_[1]... instead
    ###   my( $attrHashRef, $topic, $web ) = @_;
    forceImageThumbnailRefresh($_[1], $_[2]);
}

# CFLEWIS | 2008-04-10 | Force a refresh of an image thumbnail by
# deleting the thumbnail.
sub forceImageThumbnailRefresh
{
    my $topic = shift;
    my $web = shift;
    
    my $path = TWiki::Func::getPubDir() . "/" . $web . "/" . $topic . "/";
        
    opendir(ATTACHDIR, $path);
    
    my @files = readdir(ATTACHDIR);
    
    closedir(ATTACHDIR);
    
    foreach my $taintedFile (@files)
    {
        my $file;
        
        if ($taintedFile =~ m/(.*)/)
        {
            $file = $1;
        }
                
        if ($file =~ m/^_(\d*)___(.*)\.(jpg|png|gif|tif)$/)
        {
            # CFLEWIS | 2008-04-10 | Image plugin wrote this
            unlink $path . $file;
        }
    }
}

-- TWiki:Main.ChrisFLewis - 10 Apr 2008

True: ImagePlugin needs to listen to attachment changes, last but not least to delete unused thumbnails. However, the current ImagePlugin seems to do quite fine comparing file modification times and then recreates the thumbnails as needed. So I can't see how a thumbnail could possibly get out of date...

The only other issue is browser caching: thumbnails are named using an md5 checksum of all parameters used to render it. A good idea might be to also include the file modification time of the source image into the name of the thumbnail.

The above patch does take quite an aggressive approach to nuke all thumbnails found on a specific topic just because one new image has been added to the topic. That's probably far too agressive for image galleries with lots of thumbnails on it already. They all would need to be recomputed. Far better would be to only delete only those thumbnails that actually need to be deleted, including pending ones that arent used anymore. This however needs a small database storing which thumbnail files belong to which attachment.

-- MichaelDaum - 09 Jan 2012

ItemTemplate edit

Summary Updatet Images are not re-rendered by ImagePlugin
ReportedBy TWiki:Main.CedricWeber
Codebase
SVN Range TWiki-4.1.2, Mon, 25 Jun 2007, build 14278
AppliesTo Extension
Component ImagePlugin
Priority Normal
CurrentState Closed
WaitingFor
Checkins ImagePlugin:94a147baae01
TargetRelease n/a
ReleasedIn n/a
CheckinsOnBranches trunk
trunkCheckins ImagePlugin:94a147baae01
Release01x01Checkins
Topic revision: r7 - 29 May 2013, MichaelDaum
The copyright of the content on this website is held by the contributing authors, except where stated elsewhere. See Copyright Statement. Creative Commons License    Legal Imprint    Privacy Policy