Allfreestore
Allfreestore
DOCTYPE html>
<html>
<head>
<title>PNG to JPG Converter</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
}
#preview {
max-width: 300px;
max-height: 300px;
margin: 20px auto;
}
#output {
display: none;
}
#downloadLink {
display: none;
margin: 20px auto;
}
</style>
</head>
<body>
<h1>PNG to JPG Converter</h1>
<input type="file" id="fileInput" accept=".png">
<div id="preview"></div>
<div id="output"></div>
<a href="#" id="downloadLink" download="converted.jpg">Download Converted
JPG</a>
<script>
window.onload = function() {
const fileInput = document.getElementById('fileInput');
const preview = document.getElementById('preview');
const output = document.getElementById('output');
const downloadLink = document.getElementById('downloadLink');
fileInput.addEventListener('change', function(e) {
const file = e.target.files[0];
const reader = new FileReader();
reader.onload = function(e) {
preview.innerHTML = `<img src="${e.target.result}"
alt="Preview">`;
output.innerHTML = 'Converting...';
convertToJpg(e.target.result);
}
reader.readAsDataURL(file);
});
function convertToJpg(dataUrl) {
const canvas = document.createElement('canvas');
const img = new Image();
img.onload = function() {
canvas.width = img.width;
canvas.height = img.height;
img.src = dataUrl;
}
};
</script>
</body>
</html>