Skip to content

Commit

Permalink
Item14040: fixed attaching inline data images
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDaum committed Apr 6, 2016
1 parent 978c9bb commit 8e1d5f9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
1 change: 1 addition & 0 deletions data/System/ImagePlugin.txt
Expand Up @@ -226,6 +226,7 @@ $Foswiki::cfg{ImagePlugin}{Mode} = 'Image::Magick';
---++ Change History

%TABLE{columnwidths="7em" tablewidth="100%"}%
| 06 Apr 2016 | fixed attaching inline data images |
| 01 Apr 2016 | fixed resize rest handler returning invalid image data; \
working around buggy implementations of imagemagick core-dumping on exit |
| 26 Sep 2015 | fixed rewrite of html img tags to bail out when width/height units aren't px values; \
Expand Down
4 changes: 2 additions & 2 deletions lib/Foswiki/Plugins/ImagePlugin.pm
Expand Up @@ -30,8 +30,8 @@ use warnings;
use Foswiki::Func ();
use Foswiki::Plugins ();

our $VERSION = '7.10';
our $RELEASE = '01 Apr 2016';
our $VERSION = '7.20';
our $RELEASE = '06 Apr 2016';
our $NO_PREFS_IN_TOPIC = 1;
our $SHORTDESCRIPTION = 'Image and thumbnail services to display and alignment images using an easy syntax';
our $core;
Expand Down
20 changes: 13 additions & 7 deletions lib/Foswiki/Plugins/ImagePlugin/Core.pm
Expand Up @@ -747,17 +747,23 @@ sub beforeSaveHandler {
my $after = $5 || '';

my $suffix = $this->mimeTypeToSuffix($mimeType);
my $size = do { use bytes; length $data };
my $attachment = Digest::MD5::md5_hex($data) . '.' . $suffix;

#print STDERR "found inline image: mimeType=$mimeType, attachment=$attachment, charset=$charset, data=$size\n";

my $fh = File::Temp->new();
my $filename = $fh->filename;

binmode($fh);
print $fh $data;

my $size = do { use bytes; length $data };

my $attachment = Digest::MD5::md5_hex($data) . '.' . $suffix;

#print STDERR "found inline image: mimeType=$mimeType, attachment=$attachment, charset=$charset, data=$size, tmpfile=$filename\n";
my $offset = 0;
my $r = $size;
while ($r) {
my $w = syswrite($fh, $data, $r, $offset);
die "system write error: $!\n" unless defined $w;
$offset += $w;
$r -= $w;
}

$meta->attach(
name => $attachment,
Expand Down

0 comments on commit 8e1d5f9

Please sign in to comment.