# Dave Miller <justdave@syndicomm.com>
# Alexander J. Vincent <ajvincent@juno.com>
# Max Kanat-Alexander <mkanat@bugzilla.org>
+# Greg Hendricks <ghendricks@novell.com>
################################################################################
# Script Initialization
$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) {
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');
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;
"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 ";
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)) {
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',
</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