var resizedDataUrl = "";
function resizeAndConvert() {
var input = document.getElementById("imageInput");
var file = input.files[0];
if (!file) {
alert("Please select an image file.");
return;
}
var reader = new FileReader();
reader.onload = function (e) {
var img = new Image();
img.onload = function () {
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
var widthInches = parseFloat(document.getElementById("widthInput").value);
var heightInches = parseFloat(document.getElementById("heightInput").value);
var width = widthInches * 96; // Assuming 96 pixels per inch
var height = heightInches * 96;
canvas.width = width;
canvas.height = height;
ctx.drawImage(img, 0, 0, width, height);
var format = document.getElementById("formatSelect").value;
resizedDataUrl = canvas.toDataURL("image/" + format); // Change format here if needed
document.getElementById("output").innerHTML = '';
document.getElementById("saveButton").style.display = "inline";
}
img.src = e.target.result;
}
reader.readAsDataURL(file);
}
function saveImage() {
var link = document.createElement('a');
link.href = resizedDataUrl;
link.download = 'resized_image.' + document.getElementById("formatSelect").value;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}