%# For perfect happiness, remember two things:
%#	(1) Be content with what you've got.
%#	(2) Be sure you've got plenty.
<%PERL>
my ($buf, $stream) = ('', '');
binmode(my $upload = $ARGSRef->{upload});
while (read($upload, $buf, 8192)) {
    $stream .= $buf;
}

use Image::Size;
my ($x, $y, $type) = Image::Size::imgsize(\$stream);
return unless $x;

$stream = $m->comp('ConvertToPNG', $stream) unless $type eq 'PNG';

$ARGSRef->{alt}    ||= "$upload";
$ARGSRef->{width}  ||= $x;
$ARGSRef->{height} ||= $y;
return MIME::Base64::encode_base64($stream);
</%PERL>
<%ARGS>
$ARGSRef
</%ARGS>
