Skip to content

Commit

Permalink
Item13008:Item13001: improve rendering of images
Browse files Browse the repository at this point in the history
- only render the first frame of a gif animation generating thumbnails
- fix orientation of thumbnail as specified in the EXIF metadata
- fully specify REST security flags
- new parameter "output"
- adding support for debian packaging
  • Loading branch information
MichaelDaum committed Aug 28, 2014
1 parent 91e6746 commit 6c51509
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 19 deletions.
11 changes: 11 additions & 0 deletions .gitignore
@@ -0,0 +1,11 @@
*.gz
*.swp
pub/System/ImagePlugin/style.css
pub/System/ImagePlugin/jquery.imagetooltip.js
ImagePlugin.md5
ImagePlugin.sha1
ImagePlugin.tgz
ImagePlugin.txt
ImagePlugin.zip
ImagePlugin_installer
ImagePlugin_installer.pl
5 changes: 5 additions & 0 deletions data/System/ImagePlugin.txt
Expand Up @@ -77,6 +77,7 @@ The image name is mandatory. Further arguments are optional.
| =format= | image layout format string | set by type argument |
| =header= | text to be prepended to the html output | empty |
| =height= | integer value | image width |
| =output= | image format to convert the input source to | same as source image, except tiff and svg being converted to png |
| =href= | hyperlink when clicking on the image | url of the source image |
| =id= | (see html specs) | empty |
| =mousein= | javascript executed if moving the mouse over the image | empty |
Expand Down Expand Up @@ -223,6 +224,10 @@ $Foswiki::cfg{ImagePlugin}{Mode} = 'Image::Magick';
| License: | GPL ([[http://www.gnu.org/copyleft/gpl.html][GNU General Public License]]) |
| Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 28 Aug 2014 | only render the first frame of a gif animation generating thumbnails; \
fix orientation of thumbnail as specified in the EXIF metadata; \
fully specify REST security flags; \
new parameter =output= |
| 28 May 2014: | fixed thumbnail handling in afterRenameHandler |
| 16 Apr 2014: | brought back =thumb= image type |
| 04 Apr 2014: | flag rest handlers that don't require authentication |
Expand Down
16 changes: 16 additions & 0 deletions debian/README.source
@@ -0,0 +1,16 @@
ImagePlugin for Foswiki
-----------------------

Use this plugin to control the display and alignment of images using an easy
syntax and support for server-side resizing and thumbnailing. There are a set
of pre-defined layout formats for images as well as a free layout configurability.

Example:

%IMAGE{"Photo.jpg"
type="frame"
align="none"
caption="That's my daughter"
}%

See http://foswiki.org/Extensions/ImagePlugin for more.
5 changes: 5 additions & 0 deletions debian/changelog
@@ -0,0 +1,5 @@
foswiki-imageplugin (3.32-1+mdc0) precise; urgency=low

* Initial debianization

-- Michael Daum <debian@michaeldaumconsulting.com> Sat, 24 May 2014 18:42:40 +0200
1 change: 1 addition & 0 deletions debian/compat
@@ -0,0 +1 @@
8
19 changes: 19 additions & 0 deletions debian/control
@@ -0,0 +1,19 @@
Source: foswiki-imageplugin
Section: web
Priority: extra
Maintainer: Michael Daum <debian@michaeldaumconsulting.com>
Build-Depends: debhelper (>= 8)
Standards-Version: 3.9.3
Homepage: http://foswiki.org/Extensions/ImagePlugin

Package: foswiki-imageplugin
Architecture: all
Depends: ${perl:Depends}, ${misc:Depends}, foswiki-jqueryplugin, libwww-perl, perlmagick
Suggests: foswiki-xsendfilecontrib, libgraphics-magick-perl
Description: Image and thumbnail services to display and alignment images
Use this plugin to control the display and alignment of images using an easy
syntax and support for server-side resizing and thumbnailing. There are a set
of pre-defined layout formats for images as well as a free layout
configurability.
.
See http://foswiki.org/Extensions/ImagePlugin for more.
33 changes: 33 additions & 0 deletions debian/copyright
@@ -0,0 +1,33 @@
This work was packaged for Debian by:

Michael Daum <debian@michaeldaumconsulting.com> on Tue, 24 Apr 2012 15:54:28 +0200

It was downloaded from:

http://svn.foswiki.org

Upstream Author: Foswiki Contributors

Copyright: (from COPYRIGHT & LICENSE)

Foswiki is Copyright (C) 2008-2012 Foswiki Contributors. ALL RIGHTS RESERVED.
Foswiki Contributors are listed in the AUTHORS file in the root of this
distribution.

License:

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This package is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

On Debian systems, the complete text of the GNU General
Public License version 3 can be found in `/usr/share/common-licenses/GPL-3'.
21 changes: 21 additions & 0 deletions debian/install
@@ -0,0 +1,21 @@
data/Sandbox/ImagePluginTest.txt /var/lib/foswiki/data/Sandbox/
data/System/ImagePlugin.txt /var/lib/foswiki/data/System/
lib/Foswiki/Plugins/ImagePlugin/Config.spec /var/lib/foswiki/lib/Foswiki/Plugins/ImagePlugin/
lib/Foswiki/Plugins/ImagePlugin/Core.pm /var/lib/foswiki/lib/Foswiki/Plugins/ImagePlugin/
lib/Foswiki/Plugins/ImagePlugin/IMAGETOOLTIP.pm /var/lib/foswiki/lib/Foswiki/Plugins/ImagePlugin/
lib/Foswiki/Plugins/ImagePlugin.pm /var/lib/foswiki/lib/Foswiki/Plugins/
pub/Sandbox/ImagePluginTest/STS-32_crew.jpg /var/lib/foswiki/pub/Sandbox/ImagePluginTest/
pub/Sandbox/ImagePluginTest/Tst.png /var/lib/foswiki/pub/Sandbox/ImagePluginTest/
pub/Sandbox/ImagePluginTest/Westminstpalace.jpg /var/lib/foswiki/pub/Sandbox/ImagePluginTest/
pub/System/ImagePlugin/jquery.imagetooltip.js /var/lib/foswiki/pub/System/ImagePlugin/
pub/System/ImagePlugin/jquery.imagetooltip.js.gz /var/lib/foswiki/pub/System/ImagePlugin/
pub/System/ImagePlugin/jquery.imagetooltip.uncompressed.js /var/lib/foswiki/pub/System/ImagePlugin/
pub/System/ImagePlugin/logo.gif /var/lib/foswiki/pub/System/ImagePlugin/
pub/System/ImagePlugin/magnify-clip.png /var/lib/foswiki/pub/System/ImagePlugin/
pub/System/ImagePlugin/Makefile /var/lib/foswiki/pub/System/ImagePlugin/
pub/System/ImagePlugin/style.css /var/lib/foswiki/pub/System/ImagePlugin/
pub/System/ImagePlugin/style.css.gz /var/lib/foswiki/pub/System/ImagePlugin/
pub/System/ImagePlugin/style.uncompressed.css /var/lib/foswiki/pub/System/ImagePlugin/
pub/System/ImagePlugin/WestminstpalaceSample.png /var/lib/foswiki/pub/System/ImagePlugin/
pub/System/ImagePlugin/pixel.gif /var/lib/foswiki/pub/System/ImagePlugin/
templates/imageplugin.tmpl /var/lib/foswiki/templates/
6 changes: 6 additions & 0 deletions debian/rules
@@ -0,0 +1,6 @@
#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

%:
dh $@
1 change: 1 addition & 0 deletions debian/source/format
@@ -0,0 +1 @@
1.0
10 changes: 6 additions & 4 deletions lib/Foswiki/Plugins/ImagePlugin.pm
Expand Up @@ -31,8 +31,8 @@ our $imageCore;
our $baseWeb;
our $baseTopic;

our $VERSION = '3.33';
our $RELEASE = '3.33';
our $VERSION = '3.40';
our $RELEASE = '3.40';
our $NO_PREFS_IN_TOPIC = 1;
our $SHORTDESCRIPTION = 'Image and thumbnail services to display and alignment images using an easy syntax';

Expand Down Expand Up @@ -66,7 +66,9 @@ sub initPlugin {
sub {
getCore($baseWeb, $baseTopic, shift)->handleREST(@_);
},
authenticate => 0
authenticate => 0,
validate => 0,
http_allow => 'GET,POST',
);

# register jquery.imagetooltip plugin if jquery is isntalled
Expand Down Expand Up @@ -121,7 +123,7 @@ sub commonTagsHandler {

$text =~ s/(^|(?<!url)[-*\s(|])
(https?:
([^\s<>"]+[^\s*.,!?;:)<|][^\s]*\.(?:gif|jpe?g|png|bmp|svg)(?:\?.*)?(?=[^\w])))/
([^\s<>"]+[^\s*.,!?;:)<|][^\s]*\.(?:gif|jpe?g|png|bmp|svg)(?:\?.*)?(?=[^\w\-])))/
renderExternalLink($web, $topic, $1, $2)/geox;
putBackBlocks(\$text, $removed, 'noautolink', 'noautolink' );

Expand Down
34 changes: 29 additions & 5 deletions lib/Foswiki/Plugins/ImagePlugin/Core.pm
Expand Up @@ -489,8 +489,9 @@ sub processImage {
my $zoom = $params->{zoom} || 'off';
my $width = $params->{width} || '';
my $height = $params->{height} || '';
my $output = $params->{output} || '';

writeDebug("called processImage(web=$imgWeb, topic=$imgTopic, file=$imgFile, size=$size, crop=$crop, width=$width, height=$height, refresh=$doRefresh)");
writeDebug("called processImage(web=$imgWeb, topic=$imgTopic, file=$imgFile, size=$size, crop=$crop, width=$width, height=$height, refresh=$doRefresh, output=$output)");

$this->{errorMsg} = '';

Expand All @@ -503,7 +504,7 @@ sub processImage {
imgPath => undef,
);

if ($size || $width || $height || $doRefresh || $imgFile =~ /\.svg$/) {
if ($size || $width || $height || $doRefresh || $imgFile =~ /\.(svg|tiff?)$/ || $output) {
if (!$size) {
if ($width || $height) {
$size = $width.'x'.$height;
Expand All @@ -521,7 +522,7 @@ sub processImage {
}
writeDebug("size=$size");

$imgInfo{file} = $this->getImageFile($size, $zoom, $crop, $imgWeb, $imgTopic, $imgFile);
$imgInfo{file} = $this->getImageFile($size, $zoom, $crop, $imgWeb, $imgTopic, $imgFile, $output);
unless ($imgInfo{file}) {
$this->{errorMsg} = "(5) can't find <nop>$imgFile at <nop>$imgWeb.$imgTopic";
return;
Expand All @@ -541,7 +542,7 @@ sub processImage {
writeDebug("creating $imgInfo{file}");

my $source = $imgInfo{origImgPath};
$source .= '[0]' if $source =~ /\.gif$/i; # extract the first frame
$source .= '[0]' if $source =~ /\.gif$/i; # extract the first frame only

# read
my $error = $this->{mage}->Read($source);
Expand Down Expand Up @@ -599,6 +600,22 @@ sub processImage {
}
}

# auto orient
$error = $this->{mage}->AutoOrient();
if ($error =~ /(\d+)/) {
$this->{errorMsg} = $error;
writeDebug("Error: $error");
return undef if $1 >= 400;
}

# strip of profiles and comments
$error = $this->{mage}->Strip();
if ($error =~ /(\d+)/) {
$this->{errorMsg} = $error;
writeDebug("Error: $error");
return undef if $1 >= 400;
}

# write
$error = $this->{mage}->Write($imgInfo{imgPath});
if ($error =~ /(\d+)/) {
Expand Down Expand Up @@ -808,15 +825,22 @@ sub mirrorImage {

###############################################################################
sub getImageFile {
my ($this, $size, $zoom, $crop, $imgWeb, $imgTopic, $imgFile) = @_;
my ($this, $size, $zoom, $crop, $imgWeb, $imgTopic, $imgFile, $output) = @_;

my $imgPath = $Foswiki::cfg{PubDir}.'/'.$imgWeb.'/'.$imgTopic.'/'.$imgFile;
my $fileSize = -s $imgPath;
return unless defined $fileSize; # not found

my $digest = Digest::MD5::md5_hex($size, $zoom, $crop, $fileSize);

# force conversion of some non-webby image formats
$imgFile =~ s/\.svg$/\.png/g;
$imgFile =~ s/\.tiff?$/\.png/g;

# switch manually specified output format
if ($output && $imgFile =~ /^(.+)\.([^\.]+)$/) {
$imgFile = $1 . '.'. $output;
}

if ($imgFile =~ /^(.*)\/(.+?)$/) {
return $1."/igp_".$digest."_".$2;
Expand Down
12 changes: 6 additions & 6 deletions lib/Foswiki/Plugins/ImagePlugin/DEPENDENCIES
@@ -1,7 +1,7 @@
Image::Magick,>=6.2.4.5,cpan,Required.
LWP::UserAgent,>=0,cpan,Required.
Graphics::Magick,>=1.1.11,cpan,Optional.
Foswiki::Plugins::JQueryPlugin,>=4.90,perl,Required.
Foswiki::Contrib::XSendFileContrib,>=1.00,perl,Optional.
Image::Magick,>=6.2.4.5,cpan,Required
LWP::UserAgent,>=0,cpan,Required
Graphics::Magick,>=1.1.11,cpan,Optional
Foswiki::Plugins::JQueryPlugin,>=4.90,perl,Required
Foswiki::Contrib::XSendFileContrib,>=1.00,perl,Optional
ONLYIF ( $Foswiki::Plugins::VERSION < 2.1)
Foswiki::Plugins::ZonePlugin,>=1.0,perl,Required. required for Foswiki < 1.1
Foswiki::Plugins::ZonePlugin,>=1.0,perl,Required for Foswiki < 1.1
8 changes: 4 additions & 4 deletions templates/imageplugin.tmpl
Expand Up @@ -4,13 +4,13 @@

%TMPL:DEF{"image:plain"}%<img class='imagePlain imagePlain_$align$class' src='$src' alt='$alt' title='$title' width='$width' height='$height' $mousein $mouseout style='$style' />%TMPL:END%

%TMPL:DEF{"image:simple"}%<a %IF{"'$id'!=''" then="id='$id' "}%class='imageHref imageSimple imageSimple_$align$class' title='$title' style='$style' href='$href' ><img src='$src' alt='$alt' width='$width' height='$height' $mousein $mouseout/></a>%TMPL:END%
%TMPL:DEF{"image:simple"}%<a %IF{"'$id'!=''" then="id='$id' "}%class='imageHref imageSimple imageSimple_$align$class' title='$title' href='$href' ><img src='$src' alt='$alt' width='$width' height='$height' $mousein $mouseout style='$style' /></a>%TMPL:END%

%TMPL:DEF{"image:frame"}%<div %IF{"'$id'!=''" then="id='$id' "}%class='imageFrame imageFrame_$align$class' style='width:$framewidthpx;$style'><a class='imageHref' title='$title' href='$href'><img src='$src' alt='$alt' width='$width' height='$height' $mousein $mouseout/></a>$caption</div>%TMPL:END%
%TMPL:DEF{"image:frame"}%<div %IF{"'$id'!=''" then="id='$id' "}%class='imageFrame imageFrame_$align$class' style='width:$framewidthpx'><a class='imageHref' title='$title' href='$href'><img src='$src' alt='$alt' width='$width' height='$height' $mousein $mouseout style='$style'/></a>$caption</div>%TMPL:END%

%TMPL:DEF{"image:float"}%<div %IF{"'$id'!=''" then="id='$id' "}%class='imageFloat imageFloat_$align$class' style='$style'><a class='imageHref' title='$title' href='$href'><img src='$src' alt='$alt' width='$width' height='$height' $mousein $mouseout/></a>$caption</div>%TMPL:END%
%TMPL:DEF{"image:float"}%<div %IF{"'$id'!=''" then="id='$id' "}%class='imageFloat imageFloat_$align$class'><a class='imageHref' title='$title' href='$href'><img src='$src' alt='$alt' width='$width' height='$height' $mousein $mouseout style='$style'/></a>$caption</div>%TMPL:END%

%TMPL:DEF{"image:thumb"}%<div %IF{"'$id'!=''" then="id='$id' "}%class='imageThumb imageThumb_$align$class' style='width:$framewidthpx;$style'><a class='imageHref' title='$title' href='$href'><img src='$src' alt='$alt' width='$width' height='$height' $mousein $mouseout/></a>$caption</div>%TMPL:END%
%TMPL:DEF{"image:thumb"}%<div %IF{"'$id'!=''" then="id='$id' "}%class='imageThumb imageThumb_$align$class' style='width:$framewidthpx'><a class='imageHref' title='$title' href='$href'><img src='$src' alt='$alt' width='$width' height='$height' $mousein $mouseout style='$style'/></a>$caption</div>%TMPL:END%

%{ helper snippets }%

Expand Down

0 comments on commit 6c51509

Please sign in to comment.