summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xattachment.cgi22
-rwxr-xr-xchecksetup.pl9
-rw-r--r--defparams.pl19
-rw-r--r--template/en/default/attachment/created.html.tmpl7
4 files changed, 54 insertions, 3 deletions
diff --git a/attachment.cgi b/attachment.cgi
index e4cbe8eed..1ed7a2322 100755
--- a/attachment.cgi
+++ b/attachment.cgi
@@ -24,6 +24,7 @@
# Dave Miller <justdave@syndicomm.com>
# Alexander J. Vincent <ajvincent@juno.com>
# Max Kanat-Alexander <mkanat@bugzilla.org>
+# Greg Hendricks <ghendricks@novell.com>
################################################################################
# Script Initialization
@@ -335,7 +336,22 @@ sub validateData
$data
|| ($cgi->param('bigfile'))
|| ThrowUserError("zero_length_file");
-
+
+ # Windows screenshots are usually uncompressed BMP files which
+ # makes for a quick way to eat up disk space. Let's compress them.
+ # We do this before we check the size since the uncompressed version
+ # could easily be greater than maxattachmentsize.
+ if (Param('convert_uncompressed_images') && $cgi->param('contenttype') eq 'image/bmp'){
+ require Image::Magick;
+ my $img = Image::Magick->new(magick=>'bmp');
+ $img->BlobToImage($data);
+ $img->set(magick=>'png');
+ my $imgdata = $img->ImageToBlob();
+ $data = $imgdata;
+ $cgi->param('contenttype', 'image/png');
+ $vars->{'convertedbmp'} = 1;
+ }
+
# Make sure the attachment does not exceed the maximum permitted size
my $len = $data ? length($data) : 0;
if ($maxsize && $len > $maxsize) {
@@ -891,9 +907,11 @@ sub insert
ValidateComment(scalar $cgi->param('comment'));
my $filename = validateFilename();
validateIsPatch();
- my $data = validateData();
validateDescription();
+ # need to validate content type before data as
+ # we now check the content type for image/bmp in validateData()
validateContentType() unless $cgi->param('ispatch');
+ my $data = validateData();
my @obsolete_ids = ();
@obsolete_ids = validateObsolete() if $cgi->param('obsolete');
diff --git a/checksetup.pl b/checksetup.pl
index 7e5152628..f3a332870 100755
--- a/checksetup.pl
+++ b/checksetup.pl
@@ -368,6 +368,7 @@ my $xmlparser = have_vers("XML::Parser",0);
my $gdgraph = have_vers("GD::Graph",0);
my $gdtextalign = have_vers("GD::Text::Align",0);
my $patchreader = have_vers("PatchReader","0.9.4");
+my $imagemagick = have_vers("Image::Magick",0);
print "\n" unless $silent;
@@ -392,6 +393,14 @@ if (!$xmlparser && !$silent) {
"the XML::Parser module by running (as $::root):\n\n",
" " . install_command("XML::Parser") . "\n\n";
}
+if (!$imagemagick && !$silent) {
+ print "If you want to convert BMP image attachments to PNG to conserve\n",
+ "disk space, you will need to install the ImageMagick application\n ",
+ "Available from http://www.imagemagick.org, and the Image::Magick",
+ "Perl module by running (as $::root):\n\n",
+ " " . install_command("Image::Magick") . "\n\n";
+
+}
if ((!$gd || !$gdgraph || !$gdtextalign) && !$silent) {
print "If you you want to see graphical bug reports (bar, pie and line ";
print "charts of \ncurrent data), you should install libgd and the ";
diff --git a/defparams.pl b/defparams.pl
index 09f2a5012..49448b9d9 100644
--- a/defparams.pl
+++ b/defparams.pl
@@ -209,6 +209,15 @@ sub check_user_verify_class {
return "";
}
+sub check_image_converter {
+ my ($value, $hash) = @_;
+ if ($value == 1){
+ eval "require Image::Magick";
+ return "Error requiring Image::Magick: '$@'" if $@;
+ }
+ return "";
+}
+
sub check_languages {
my @languages = split /[,\s]+/, trim($_[0]);
if(!scalar(@languages)) {
@@ -1291,6 +1300,16 @@ Reason: %reason%
default => '0',
checker => \&check_numeric
},
+
+ {
+ name => 'convert_uncompressed_images',
+ desc => 'If this option is on, attachments with content type image/bmp ' .
+ 'will be converted to image/png and compressed before uploading to'.
+ 'the database to conserve disk space.',
+ type => 'b',
+ default => 0,
+ checker => \&check_image_converter
+ },
{
name => 'chartgroup',
diff --git a/template/en/default/attachment/created.html.tmpl b/template/en/default/attachment/created.html.tmpl
index 9bfb36caf..ef318f575 100644
--- a/template/en/default/attachment/created.html.tmpl
+++ b/template/en/default/attachment/created.html.tmpl
@@ -44,7 +44,12 @@
</h2>
[% PROCESS "bug/process/bugmail.html.tmpl" mailing_bugid = bugid %]
-
+ [% IF convertedbmp %]
+ <p>
+ <b>Note:</b> [% terms.Bugzilla %] automatically converted your BMP image file to a
+ compressed PNG format.
+ </p>
+ [% END %]
[% IF contenttypemethod == 'autodetect' %]
<p>
<b>Note:</b> [% terms.Bugzilla %] automatically detected the content type