From d79c2c86ef0b69c4250642e3709f22a34fe7c8a0 Mon Sep 17 00:00:00 2001 From: "myk%mozilla.org" <> Date: Sat, 30 Jul 2005 07:46:39 +0000 Subject: Fix for bug 302083: automatically converts BMP files to PNG files to conserve disk space; patch by Greg Hendricks; r=myk, a=myk --- attachment.cgi | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'attachment.cgi') diff --git a/attachment.cgi b/attachment.cgi index e4cbe8eed..1ed7a2322 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'); -- cgit v1.2.3-24-g4f1b