Auto convert uploaded BMP files to PNG

Post about your customizations to share with others.

Moderators: Developer, Contributor

Post Reply
mgerben
Posts: 11
Joined: 15 Feb 2005, 07:42
Location: Netherlands
Contact:

Auto convert uploaded BMP files to PNG

Post by mgerben »

I disabled uploading of files because that one user who doesn't know how to convert a screenshot to a GIF file can fill my whole database once they find out they can attach 2.2MB screendumps in BMP format.
Of course I can set an upload limit or disable 'BMP' format, but then I'd have to explain to every user why, how to convert to GIF, and so on...
So I hacked in a line to detect a BMP upload and automatically convert it to the much smaller PNG format.

I use ImageMagick for it which is almost a standard on any recent Linux distro.

It's a bit hacked, but I'll work with anyone who wants to improve on it and integrate it in Mantis.
vboctor
Site Admin
Posts: 1293
Joined: 13 Feb 2005, 22:11
Location: Redmond, Washington
Contact:

Post by vboctor »

Sounds like a useful feature to integrate into Mantis. I think we can add it, if we achieve the following:

1. Have a config variable that determines whether such conversion should be automatically done or not.

2. If the config variable is ON, then the required library / platform should be auto-detected, if not found, then the bmp should be attached as normal.

3. The code should follow Mantis standards.

4. It should be easy to support other libraries in the future to do such conversions. For example, the code should be able to look for several libraries, and use the first one found to do the conversions.

Regards,
Victor.
mgerben
Posts: 11
Joined: 15 Feb 2005, 07:42
Location: Netherlands
Contact:

Post by mgerben »

Hi Victor.

It is indeed very useful.

I fully concur with you on all four points.

I'm not proud of the way I've implemented it at the moment. It's a quick and dirty fix with no error-checking.
In the file-upload api I check the extension and then I use 'shell_exec' to call the ImageMagick-convert module without even checking if it's available - hence, it works for me because I have ImageMagick.

Perhaps the Gallery-project is an interesting place to see how they use either ImageMagick or NetPBM.

As I understand it, ImageMagick can be used as a package or an object, but that's where it ends for me: I'm no PHP-hacker; I'm a C++ hacker.


Would you like to have my sourcecode? You can reach me at mgerben@yahoo.com; I'll send it to you.


As for the configuration parameter - it's required if this is included in Mantis, but personally I feel that the config-values could/should migrate to a configuration page and be stored in the database - much friendlier, and much easier to migrate to a new s/w version. Your thoughts?
mikewhit
Posts: 20
Joined: 18 Feb 2005, 10:40
Location: Shropshire UK

Reason to convert

Post by mikewhit »

A halfway house might be to ask, on detection of a .bmp upload, whether:
  • the .bmp file itself represents the problem (e.g. your application being bugtracked creates a broken .bmp file) in which case you want the file uploaded as-is, unconverted
  • or (default) whether it's just a screenshot/picture showing the problem, in which case it could be PNG'd.
That would cover most cases of gratuitous .bmps. But it should still be possible to upload a pukka .bmp without it getting PNGd, if necessary.
Last edited by mikewhit on 18 Mar 2005, 13:50, edited 2 times in total.
mgerben
Posts: 11
Joined: 15 Feb 2005, 07:42
Location: Netherlands
Contact:

Can't tell my users what to upload

Post by mgerben »

Hi Mikewhit,

Unfortunately, my users take it rather personal if I or anyone else should tell them that the screenshot that they feel is important enough to upload, isn't relevant enough or doesn't describe the situation.
Basically I want to enable this feature to my users without guidelines or restrictions.
Some users upload more than others, some upload trivial screenshots some of the time, but most of the time it's useful; and with this fix (sourcecode just posted in #5227) they can upload freely, without serious impact on the database.

Btw I even disabled JPG uploads because they're bigger than converted BMPs. One user was uploading JPGs to do his best to help keep the size small - unaware that the conversion works better.
Narcissus
Developer
Posts: 338
Joined: 17 Feb 2005, 09:45

Post by Narcissus »

Hi mgerben: I think Mikewhit wasn't actually trying to say that a screenshot is not necessarily important (despite what the user thinks), but was referring to the fact that some attachments need to be in a particular format, whereas others (screenshots, for example) can be converted automatically. Those that need to be a BMP (for example) could be an attachment of a file that in itself is incorrect (imagine a picture editor that corrupts BMPs: you may need to upload the BMP itself, not a converted version of it, to show the actual corruption of data).

In regards to this I don't think you should ask them if they intend the data to stay the same after uploading it. I would prefer to see a checkbox in the file upload section with a label like "Convert this to another format if possible to make it smaller". Maybe have this ticked by default.

Along with Victor's comments, I would like to see the code work more 'generically'. Off the top of my head, I would hope for two things:
1) The ability to define lists of what are essentially 'functionally equivalent' filetypes. This way I could give a list of 'BMP, GIF, PNG, JPG' for example and have the code encode from any of these extensions into all of the rest. From there, determine the smallest file and use that one.
2) The ability to associate with each of these groups of functional equivalence a conversion routine / tool. That way I could have a group for graphics that uses one tool and a group for documents that uses another tool, for example.

Lincoln.
mgerben
Posts: 11
Joined: 15 Feb 2005, 07:42
Location: Netherlands
Contact:

Post by mgerben »

Yep, you're right, I read Mikewith's post a little bit too fast.

As for conversions; it would be beautiful to be able to specify and conigure multiple filters and automatic conversions (maybe even a DOC to PDF filter :-) ), but my approach has always been an 90-10 attitude.
Just an automatic filetype conversion could be a Sourceforge project on its own, and here it's just a simple funtion to save a few MBs in the database.

Agreed; a BMP could be the problem instead of representing it, but it would be a lot of work, for not too many projects (how many of you are working on projects that generate BMPs and have a problem with the generated BMPs?)
With this little automatic conversion, I'm 90% there, for 10% of the trouble.

I'm sure that your experience, just like mine, is that that final 10% of the functionality is what costs you the extra 90% of the effort.
Post Reply