]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Fix for bug 302083: automatically converts BMP files to PNG files to conserve disk...
authormyk%mozilla.org <>
Sat, 30 Jul 2005 07:46:39 +0000 (07:46 +0000)
committermyk%mozilla.org <>
Sat, 30 Jul 2005 07:46:39 +0000 (07:46 +0000)
attachment.cgi
checksetup.pl
defparams.pl
template/en/default/attachment/created.html.tmpl

index e4cbe8eed76e6099b788a67e163d8dd901ab6a85..1ed7a2322091c1fc351755956258a38b1b9866f1 100755 (executable)
@@ -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');
index 7e515262898b7f9edf92770d491d575a9caf7c7d..f3a332870f4d20436c776ce3ecace2bcedc78340 100755 (executable)
@@ -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 ";
index 09f2a50123c6eb0fec601a4cc7e83a6529281994..49448b9d998ecfc39694ce7effc3f859bec159bd 100644 (file)
@@ -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',
index 9bfb36caf253d4419169d8bb531b195873c28422..ef318f5759c1e4cc779dd0b3a74f3a548f5c9cb5 100644 (file)
       </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