Skip to content

Commit

Permalink
Item13024: implemented =frame= and =layer= params
Browse files Browse the repository at this point in the history
... for thumbnail extraction from videos, animations and layered images
  • Loading branch information
MichaelDaum committed Sep 4, 2014
1 parent 6c51509 commit 2d2e932
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 18 deletions.
8 changes: 4 additions & 4 deletions data/Sandbox/ImagePluginTest.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" comment="reprev" date="1397816603" format="1.1" reprev="4" version="4"}%
%META:TOPICINFO{author="ProjectContributor" comment="" date="1409847733" format="1.1" version="1"}%
---+!! Exhaustive Test Page for !ImagePlugin
%TOC%

Expand Down Expand Up @@ -87,6 +87,6 @@ colon before "image" in an intra-wiki link, like this
%IMAGE{":STS-32_crew.jpg|STS-32 crew"}%


%META:FILEATTACHMENT{name="Westminstpalace.jpg" attr="h" comment="" date="1225717138" path="Westminstpalace.jpg" size="19790" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="Tst.png" attr="h" comment="" date="1225717138" path="Tst.png" size="499" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="STS-32_crew.jpg" attr="h" comment="" date="1225717138" path="STS-32_crew.jpg" size="49583" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="Westminstpalace.jpg" attr="h" comment="" date="1409847733" path="Westminstpalace.jpg" size="19790" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="Tst.png" attr="h" comment="" date="1409847733" path="Tst.png" size="499" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="STS-32_crew.jpg" attr="h" comment="" date="1409847733" path="STS-32_crew.jpg" size="49583" user="ProjectContributor" version="1"}%
9 changes: 6 additions & 3 deletions data/System/ImagePlugin.txt
@@ -1,4 +1,4 @@
%META:TOPICINFO{author="ProjectContributor" date="1308213511" format="1.1" version="3"}%
%META:TOPICINFO{author="ProjectContributor" date="1409847733" format="1.1" version="1"}%
---+!! <nop>%TOPIC%
%TOC%

Expand Down Expand Up @@ -75,6 +75,8 @@ The image name is mandatory. Further arguments are optional.
| =desc= | description text | title text |
| =footer= | text to be appended to the html output | empty |
| =format= | image layout format string | set by type argument |
| =frame= | extract a specific frame or layer from the source file; this comes in handy when rendering a thumbnail for a video clip |
| =layer= | alias for =frame= |
| =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 |
Expand Down Expand Up @@ -224,6 +226,7 @@ $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; |
| 04 Sep 2014 | implemented =frame= and =layer= parameter for thumbnail extraction from videos, animations and layered images |
| 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; \
Expand Down Expand Up @@ -294,5 +297,5 @@ $Foswiki::cfg{ImagePlugin}{Mode} = 'Image::Magick';
| Support: | Foswiki:Support/%TOPIC% |


%META:FILEATTACHMENT{name="WestminstpalaceSample.png" attr="h" comment="" date="1185796830" path="WestminstpalaceSample.png" size="107728" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="logo.gif" attachment="logo.gif" attr="h" date="1266012865" path="http://www.google.com/intl/en_ALL/images/logo.gif" size="8558" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="WestminstpalaceSample.png" attr="h" comment="" date="1409847733" path="WestminstpalaceSample.png" size="107728" user="ProjectContributor" version="1"}%
%META:FILEATTACHMENT{name="logo.gif" attachment="logo.gif" attr="h" date="1409847733" path="http://www.google.com/intl/en_ALL/images/logo.gif" size="8558" user="ProjectContributor" version="1"}%
4 changes: 2 additions & 2 deletions lib/Foswiki/Plugins/ImagePlugin.pm
Expand Up @@ -31,8 +31,8 @@ our $imageCore;
our $baseWeb;
our $baseTopic;

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

Expand Down
36 changes: 28 additions & 8 deletions lib/Foswiki/Plugins/ImagePlugin/Core.pm
Expand Up @@ -504,7 +504,7 @@ sub processImage {
imgPath => undef,
);

if ($size || $width || $height || $doRefresh || $imgFile =~ /\.(svg|tiff?)$/ || $output) {
if ($size || $width || $height || $doRefresh || $imgFile =~ /\.(svg|tiff?|xcf|psd)$/ || $output) {
if (!$size) {
if ($width || $height) {
$size = $width.'x'.$height;
Expand All @@ -521,8 +521,24 @@ sub processImage {
}
}
writeDebug("size=$size");
my $frame;
if (defined $params->{layer}) {
$frame = $params->{layer};
} elsif (defined $params->{frame}) {
$frame = $params->{frame};
} else {
$frame = '0' if $imgInfo{origImgPath} =~/\.gif$/;
}
if (defined $frame) {
$frame =~ s/^.*?(\d+).*$/$1/g;
$frame = 1000 if $frame > 1000; # for security
$frame = 0 if $frame < 0;
$frame = '['.$frame.']';
} else {
$frame = '';
}

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

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

# read
my $error = $this->{mage}->Read($source);
Expand All @@ -551,6 +566,12 @@ sub processImage {
return undef if $1 >= 400;
}

# merge layers
if ($imgFile =~ /\.(xcf|psd)$/i) {
$this->{mage} = $this->{mage}->Layers(method=>'merge');
}


# scale
if ($size) {
my $geometry = $size;
Expand Down Expand Up @@ -825,17 +846,16 @@ sub mirrorImage {

###############################################################################
sub getImageFile {
my ($this, $size, $zoom, $crop, $imgWeb, $imgTopic, $imgFile, $output) = @_;
my ($this, $size, $zoom, $crop, $frame, $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);
my $digest = Digest::MD5::md5_hex($size, $zoom, $crop, $frame, $fileSize);

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

# switch manually specified output format
if ($output && $imgFile =~ /^(.+)\.([^\.]+)$/) {
Expand Down
2 changes: 1 addition & 1 deletion pub/System/ImagePlugin/jquery.imagetooltip.uncompressed.js
Expand Up @@ -11,7 +11,7 @@ jQuery(function($) {

$this.addClass("jqInitedImageTooltip");

if (typeof(opts.image) !== 'undefined' && opts.image.match(/jpe?g|gif|png|bmp|svg/i)) {
if (typeof(opts.image) !== 'undefined' && opts.image.match(/jpe?g|gif|png|bmp|svg|xcf|psd|tiff?/i)) {
$this.tooltip({
show: {
delay: 350
Expand Down

0 comments on commit 2d2e932

Please sign in to comment.