How to Convert Images to BMP Format using JavaScript
One of the oldest image format types, BMP still has its uses today — most importantly as a better quality-retaining cousin of the JPG format, which is characterized by its lossy-ness. If you’re looking to make quick BMP image conversions, we have the perfect tool for you: our Bitmap Conversion API will automatically convert dozens of common input image file types to BMP in the blink of an eye. No more worrying about quality loss with JPG! It’s easy to use this API by structuring your API call with ready-to-run JavaScript code examples included below. To authenticate access, simply register a free account on our website and copy the API key you’ll receive into the relevant snippet (for both XHR and jQuery methods).
If you’re using the JavaScript XHR feature, structure your API call like so:
var data = new FormData();
data.append("imageFile", fileInput.files[0], "file");
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});xhr.open("POST", "https://api.cloudmersive.com/image/convert/to/bmp");xhr.setRequestHeader("Apikey", "YOUR-API-KEY-HERE");xhr.send(data);
To use jQuery, first install the library using the following command:
bower install jquery
Then use the below code to structure your call:
var form = new FormData();
form.append("imageFile", fileInput.files[0], "file");var settings = {
"url": "https://api.cloudmersive.com/image/convert/to/bmp",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "multipart/form-data",
"Apikey": "YOUR-API-KEY-HERE"
},
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};$.ajax(settings).done(function (response) {
console.log(response);
});
All done — nice & easy.