View Issue Details

IDProjectCategoryView StatusLast Update
0005227mantisbtfeaturepublic2011-06-21 03:43
Reportermgerben Assigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
Status newResolutionopen 
Product Version0.19.2 
Summary0005227: Feature rqst: Automatic conversion of attached screendumps to Jpeg, PNG or GIF
Description

I have disabled uploading files to our Mantis because our users will use it to attach screendumps - in full BMP-format, so that's 2.2MB per image.
That's too much, but I would like screendumps.
Wouldn't this world be a better place if Mantis could recognize a BMP and convert it to a much smaller grapics format?

TagsNo tags attached.

Relationships

related to 0005015 closedgrangeway Upload screenshots/screen captures and clipboard images 

Activities

mgerben

mgerben

2005-02-10 08:36

reporter   ~0009281

Last edited: 2005-02-10 09:22

Also see 0005015 rougly about the same thing.
I hacked an automatic BMP->PNG conversion in file_api.php.
A full screendyump of 2MB is converted to 29KB. Pretty impressive, and nice for server diskspace and bandwith.
I'm now going to allow screenshot-uploads to our users.

epu

epu

2005-03-16 17:01

reporter   ~0009560

you mention you're using imagemagick. if you can attach your patch here, let's integrate it with config options (like other 3rd party / optional tools) and make it official.

mgerben

mgerben

2005-03-17 04:22

reporter   ~0009568

No problem.
I don't know what the standard for patches is, so here's my code:

File is core/file_api.php

At the bottom I added this function to remove the extension from a filename:

--------------------

Get basename given the filename or its full path.

function file_get_basename( $p_filename ) {
$ext = '';
$dot_found = false;
$i = strlen( $p_filename ) - 1;
while ( $i >= 0 ) {
if ( '.' == $p_filename[$i] ) {
$dot_found = true;
break;
}

# found a directoryarker before a period.
if ( ( $p_filename[$i] == "/" ) || ( $p_filename[$i] == "\\" ) ) {
  return $p_filename;
}

$i--;

}

if ( $dot_found ) {
return ( substr ($p_filename, 0, $i ) );
} else {
return $p_filename;
}
}

################################################### the end

Then in function 'file_add' I add the following - the first IF statement is still part of the original code:

if ( !file_type_check( $p_file_name ) ) {
trigger_error( ERROR_FILE_NOT_ALLOWED, ERROR );
}

Convert all bmp files to png - here's the bit I added:

$t_bmp2png = (strtolower( file_get_extension($p_file_name)) == "bmp" );
if ($t_bmp2png)
{
$png_filename = file_get_basename($p_file_name) . '.png';
$p_file_name = $png_filename;

    if ( 1 )
    {
            # move from tempfile to tempfile.bmp
            $tmp_file_bmp = file_get_basename($p_tmp_file) . '.bmp';
            $tmp_file_png = file_get_basename($p_tmp_file) . '.png';
            $dummy = shell_exec("/bin/mv -f $p_tmp_file $tmp_file_bmp");

            # then convert tempfile.bmp to tempfile.png
            $dummy = shell_exec("/usr/bin/convert $tmp_file_bmp $tmp_file_png");

            # then move tempfile.png back to tempfile
            $dummy = shell_exec("/bin/mv -f $tmp_file_png $p_tmp_file");

    }

}

#################################### rest of 'file add'.

Notes:

  • the 'if (1)' is the place to decide whether to run this conversion for DISK based files, DATABASE files, or both. Currently it will convert every time.
  • I convert the file to PNG and I change the filename that's in the parameter $p_filename. That way the converted filename shows up on the screen, and not the 'bmp' filename.
  • I use hardcoded calls to ImageMagic's 'convert', and then some hardcoded calls to 'mv' to change the filename. This is not how it should be done. I believe ImageMagick has a PHP plugin to perform conversions. I'm no PHP wizzard, so I did it the dirty way.
  • There is no failsafe. If the conversion fails, for instance because 'convert' cannot be found, this is not detected and the uploaded file is lost.
  • The rest of the code works without changes because
    a) the filename is changed and
    b) the variable containing the filename is changed accordingly.
    To the rest of the software it looks as if a PNG file was uploaded instead of a BMP file.

Good luck with it.