Pages

Saturday, 30 November 2024

Online Photo Editor Tool



Online Photo Editor

Online Photo Editor

/* General Styling */ body { font-family: Arial, sans-serif; margin: 0; padding: 0; display: flex; flex-direction: column; align-items: center; background: linear-gradient(to right, #4facfe, #00f2fe); color: #333; } header { text-align: center; margin: 20px 0; } h1 { color: white; text-shadow: 2px 2px 5px rgba(0, 0, 0, 0.3); } /* Editor Container */ .editor-container { display: flex; flex-wrap: wrap; justify-content: center; align-items: flex-start; gap: 20px; max-width: 1200px; width: 100%; padding: 20px; } .canvas-container { flex: 1; max-width: 600px; background-color: white; border: 2px solid #ccc; border-radius: 10px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); overflow: hidden; } canvas { display: block; width: 100%; } /* Tools Container */ .tools-container { flex: 0.4; max-width: 300px; background: #fff; border: 2px solid #ccc; border-radius: 10px; padding: 20px; box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); } .tool { margin-bottom: 15px; } .tool label { font-size: 14px; display: block; margin-bottom: 5px; } .tool input, .tool button { width: 100%; padding: 10px; font-size: 16px; border: 1px solid #ccc; border-radius: 5px; } .tool button { background-color: #4facfe; color: white; cursor: pointer; transition: 0.3s; } .tool button:hover { background-color: #00f2fe; } .tool input[type="color"] { width: 100%; height: 40px; cursor: pointer; } const canvas = new fabric.Canvas('photoCanvas', { width: 600, height: 400, backgroundColor: '#ffffff', }); // Image Upload document.getElementById('imageUpload').addEventListener('change', (event) => { const file = event.target.files[0]; if (file) { const reader = new FileReader(); reader.onload = function (f) { fabric.Image.fromURL(f.target.result, (img) => { img.scaleToWidth(400); canvas.add(img); canvas.setActiveObject(img); }); }; reader.readAsDataURL(file); } }); // Add Text document.getElementById('addTextButton').addEventListener('click', () => { const text = new fabric.Textbox('Edit Me', { left: 100, top: 100, fontSize: 20, fill: '#000', }); canvas.add(text); canvas.setActiveObject(text); }); // Delete Selected Object document.getElementById('deleteSelectedButton').addEventListener('click', () => { const activeObject = canvas.getActiveObject(); if (activeObject) { canvas.remove(activeObject); } }); // Change Background Color document.getElementById('backgroundColor').addEventListener('change', (event) => { canvas.setBackgroundColor(event.target.value, canvas.renderAll.bind(canvas)); }); // Download Image document.getElementById('downloadButton').addEventListener('click', () => { const link = document.createElement('a'); link.download = 'edited_image.png'; link.href = canvas.toDataURL(); link.click(); });