Commit d79c2c86 authored by myk%mozilla.org's avatar myk%mozilla.org

Fix for bug 302083: automatically converts BMP files to PNG files to conserve…

Fix for bug 302083: automatically converts BMP files to PNG files to conserve disk space; patch by Greg Hendricks; r=myk, a=myk
parent f55027e7
......@@ -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');
......
......@@ -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 ";
......
......@@ -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',
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment