Changeset 5548


Ignore:
Timestamp:
11/17/09 14:43:03 (3 years ago)
Author:
MichaelDaum
Message:

Item8332: added zoom parameter for better thumbnailing

Location:
trunk/ImagePlugin
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/ImagePlugin/data/System/ImagePlugin.txt

    r5127 r5548  
    9393| =refresh= | on/off/img to trigger recomputing images | off | 
    9494| =size=  | geometry specification | image geometry  | 
     95| =zoom=  | on/off | if set to "on" scaling up images is allowed, otherwise it downscales only | off | 
    9596| =style= | (see html specs) | empty | 
    9697| =title= | title text | *alt* value | 
     
    118119measure use the =width= and =height= arguments. 
    119120 
     121Note, that you must set =zoom="on"= to scale images up. Otherwise images smaller 
     122than the given gemoentry will stay as hey are. For instance, when generating thumbnails 
     123it is preferable to keep small icons as they are instead of bloating them up 
     124to a standard thumbnail size. 
    120125 
    121126---+++ Format specification 
     
    176181| =height= | height of thumbnail  | | 
    177182| =size= | geometry of thumbnail  | | 
     183| =zoom= | switch on/off upscaling  | | 
    178184| =refresh= | on/off/img to trigger recomputing images | off | 
    179185 
     
    239245|  Version: | %$VERSION% | 
    240246|  Change History: | <!-- versions below in reverse order -->&nbsp; | 
     247|  17 Nov 2009: | added =zoom= parameter; fixed manual refresh via url params | 
    241248|  24 Sep 2009: | updated =imageplugin.template= to help XHTML validation (stop rendering empty id attribute) | 
    242249|  14 Sep 2009: | using Foswiki's proxy settings instead of ENV; disabled tooltip previews for Internet Explorers | 
     
    277284 
    278285 
    279 %META:FILEATTACHMENT{name="WestminstpalaceSample.png" attr="h" autoattached="1" comment="" date="1185796830" path="WestminstpalaceSample.png" size="107728" user="ProjectContributor" version="1"}% 
     286%META:FILEATTACHMENT{name="WestminstpalaceSample.png" attr="h" comment="" date="1185796830" path="WestminstpalaceSample.png" size="107728" user="ProjectContributor" version="1"}% 
  • trunk/ImagePlugin/lib/Foswiki/Plugins/ImagePlugin.pm

    r4910 r5548  
    3232 
    3333$VERSION = '$Rev$'; 
    34 $RELEASE = '2.12'; 
     34$RELEASE = '2.20'; 
    3535 
    36 use Foswiki::Plugins; 
    37 use Foswiki::Render; 
     36use Foswiki::Plugins (); 
     37use Foswiki::Render (); 
    3838 
    3939############################################################################### 
  • trunk/ImagePlugin/lib/Foswiki/Plugins/ImagePlugin/Core.pm

    r4910 r5548  
    102102  my $height = $query->param('height') || ''; 
    103103  my $size = $query->param('size') || ''; 
     104  my $zoom = $query->param('zoom') || 'off'; 
    104105  my $refresh = $query->param('refresh') || ''; 
    105106  $refresh = ($refresh =~ /^(on|1|yes|img)$/g)?1:0; 
     
    107108  #writeDebug("processing image"); 
    108109  my $imgInfo = $this->processImage($imgWeb, $imgTopic, $imgFile,  
    109     $size, $width, $height, $refresh); 
     110    $size, $zoom, $width, $height, $refresh); 
    110111  unless ($imgInfo) { 
    111112    Foswiki::Func::writeWarning("ImagePlugin - $this->{errorMsg}"); 
     
    153154  $params->{mouseout} ||= ''; 
    154155  $params->{style} ||= ''; 
     156  $params->{zoom} ||= 'off'; 
    155157  $params->{tooltip} ||= 'off'; 
    156158  $params->{tooltipwidth} ||= '300'; 
     
    305307  my $imgInfo =  
    306308    $this->processImage($imgWeb, $imgTopic, $origFile,  
    307       $params->{size}, $params->{width}, $params->{height}, $doRefresh); 
     309      $params->{size}, $params->{zoom}, $params->{width}, $params->{height}, $doRefresh); 
    308310 
    309311  unless ($imgInfo) { 
     
    442444# returns undef on error 
    443445sub processImage { 
    444   my ($this, $imgWeb, $imgTopic, $imgFile, $size, $width, $height, $doRefresh) = @_; 
    445  
    446   writeDebug("called processImage($imgWeb, $imgTopic, $imgFile, $size, $width, $height, $doRefresh)"); 
     446  my ($this, $imgWeb, $imgTopic, $imgFile, $size, $zoom, $width, $height, $doRefresh) = @_; 
     447 
     448  writeDebug("called processImage($imgWeb, $imgTopic, $imgFile, $size, $zoom, $width, $height, $doRefresh)"); 
    447449 
    448450  $this->{errorMsg} = ''; 
     
    460462  $imgInfo{origHeight} ||= 0; 
    461463 
     464  if ($size) { 
     465    if ($zoom ne 'on' && ($size > $imgInfo{origHeight} || $size > $imgInfo{origWidth})) { 
     466      writeDebug("not zooming to size $size"); 
     467      $size = ''; 
     468    } 
     469  } 
     470 
    462471  if ($size || $width || $height || $doRefresh) { 
    463472    # read orig width and height 
    464473    if ($width || $height) { 
     474 
    465475      # keep aspect ratio 
    466476      my $aspect = $imgInfo{origWidth} ? $imgInfo{origHeight} / $imgInfo{origWidth} : 0; 
    467477      my $newHeight = $imgInfo{origHeight}; 
    468478      my $newWidth = $imgInfo{origWidth}; 
    469       if ($width && $newWidth > $width) { 
     479 
     480      if ($width && $imgInfo{origWidth} > $width) { # scale down width 
    470481        $newHeight = $width * $aspect; 
    471482        $newWidth = $width; 
    472483      } 
    473       if ($height && $newHeight > $height) { 
     484 
     485      if ($height && $newHeight > $height) { # scale down height 
    474486        $newWidth = $aspect ? $height / $aspect : 0; 
    475487        $newHeight = $height; 
    476488      } 
     489 
     490      if ($zoom ne 'on' && ($newHeight > $imgInfo{origHeight} || $newWidth > $imgInfo{origWidth})) { 
     491        writeDebug("not zooming"); 
     492        $newHeight = $imgInfo{origHeight}; 
     493        $newWidth = $imgInfo{origWidth}; 
     494      } 
     495 
    477496      $width = int($newWidth+0.5); 
    478497      $height = int($newHeight+0.5); 
    479       #writeDebug("origWidth=$imgInfo{origWidth} origHeight=$imgInfo{origHeight} aspect=$aspect width=$width height=$height"); 
    480     } 
    481        
     498      writeDebug("origWidth=$imgInfo{origWidth} origHeight=$imgInfo{origHeight} aspect=$aspect width=$width height=$height"); 
     499    } 
     500 
    482501    my $newImgFile = $this->getImageFile($width, $height, $size, $imgFile); 
    483502    my $newImgPath = $imgPath.'/'.$newImgFile; 
     
    680699    my $topicInfo = $meta->get('TOPICINFO'); 
    681700    $attachment->{name} = $baseFilename; 
    682     $attachment->{attachment} = $filename; 
     701    $attachment->{attachment} = $baseFilename; # BTW: not documented in System.MetaData  
    683702    $attachment->{date} = time(); 
    684703    $attachment->{version} ||= 1; 
Note: See TracChangeset for help on using the changeset viewer.