From: myk%mozilla.org <> Date: Sat, 30 Jul 2005 07:46:39 +0000 (+0000) Subject: Fix for bug 302083: automatically converts BMP files to PNG files to conserve disk... X-Git-Tag: bugzilla-2.21.1~154 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d79c2c86ef0b69c4250642e3709f22a34fe7c8a0;p=thirdparty%2Fbugzilla.git Fix for bug 302083: automatically converts BMP files to PNG files to conserve disk space; patch by Greg Hendricks; r=myk, a=myk --- diff --git a/attachment.cgi b/attachment.cgi index e4cbe8eed7..1ed7a23220 100755 --- a/attachment.cgi +++ b/attachment.cgi @@ -24,6 +24,7 @@ # Dave Miller # Alexander J. Vincent # Max Kanat-Alexander +# Greg Hendricks ################################################################################ # 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 7e51526289..f3a332870f 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 09f2a50123..49448b9d99 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 9bfb36caf2..ef318f5759 100644 --- a/template/en/default/attachment/created.html.tmpl +++ b/template/en/default/attachment/created.html.tmpl @@ -44,7 +44,12 @@ [% PROCESS "bug/process/bugmail.html.tmpl" mailing_bugid = bugid %] - + [% IF convertedbmp %] +

+ Note: [% terms.Bugzilla %] automatically converted your BMP image file to a + compressed PNG format. +

+ [% END %] [% IF contenttypemethod == 'autodetect' %]

Note: [% terms.Bugzilla %] automatically detected the content type