tooooly / index.html
Saad4web's picture
Play Role Web Dev Senior TensorflowJs and Start Build Web App For Next Tools Using TfJs and html5 and tailwind css with professional and good logic and make each tool on page and add nav tab : Image Compressor You can compress images and reduce their size. This process may reduce the quality of the image. Image Resizer You can change the dimensions (width and height) of the image. Image Rotate & Reflect You can rotate and reflect the image at any angle you want. Watermark You can add any text you want to the image as watermark. - Initial Deployment
b6ea795 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Processing Toolkit | TensorFlow.js</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@latest"></script>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-image@latest"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script>
tailwind.config = {
theme: {
extend: {
colors: {
primary: '#5a67d8',
secondary: '#4c51bf',
dark: '#1a202c',
light: '#f8fafc'
}
}
}
}
</script>
</head>
<body class="bg-gray-100 text-gray-800">
<div class="min-h-screen flex flex-col">
<!-- Header -->
<header class="bg-gradient-to-r from-primary to-secondary shadow-lg">
<div class="container mx-auto px-4 py-6">
<div class="flex flex-col md:flex-row justify-between items-center">
<div class="flex items-center space-x-2 mb-4 md:mb-0">
<div class="w-10 h-10 rounded-full bg-white flex items-center justify-center">
<i class="fas fa-image text-primary text-xl"></i>
</div>
<h1 class="text-white text-2xl font-bold">Image Processing Toolkit</h1>
</div>
<nav class="flex space-x-2">
<button id="compressor-tab" class="nav-tab active" data-tab="compressor">
<i class="fas fa-compress-alt mr-2"></i> Compressor
</button>
<button id="resizer-tab" class="nav-tab" data-tab="resizer">
<i class="fas fa-expand-alt mr-2"></i> Resizer
</button>
<button id="rotator-tab" class="nav-tab" data-tab="rotator">
<i class="fas fa-sync-alt mr-2"></i> Rotate/Reflect
</button>
<button id="watermark-tab" class="nav-tab" data-tab="watermark">
<i class="fas fa-tint mr-2"></i> Watermark
</button>
</nav>
</div>
</div>
</header>
<!-- Main Content -->
<main class="flex-grow container mx-auto px-4 py-8">
<!-- Loading Indicator -->
<div id="loading" class="hidden fixed inset-0 bg-black bg-opacity-50 z-50 flex items-center justify-center">
<div class="bg-white p-6 rounded-lg shadow-xl flex flex-col items-center">
<div class="w-16 h-16 border-t-2 border-primary rounded-full animate-spin"></div>
<p class="mt-4 text-lg font-medium">Processing image...</p>
</div>
</div>
<!-- Tool Sections -->
<div class="tool-section" id="compressor-section">
<div class="card">
<h2 class="card-title"><i class="fas fa-compress-alt mr-2"></i> Image Compressor</h2>
<p class="text-gray-600 mb-6">Reduce image file size while maintaining reasonable quality</p>
<div class="flex flex-col md:flex-row gap-8">
<!-- Input Section -->
<div class="flex-1">
<div class="bg-gray-50 rounded-lg border border-dashed border-gray-300 p-6 text-center cursor-pointer relative hover:border-primary transition-colors duration-300" id="upload-area">
<input type="file" id="image-input" class="absolute inset-0 w-full h-full opacity-0 cursor-pointer" accept="image/*">
<i class="fas fa-cloud-upload-alt text-5xl text-gray-400 mb-4"></i>
<h3 class="text-lg font-medium mb-2">Upload Image</h3>
<p class="text-sm text-gray-500 max-w-xs mx-auto">Click to browse or drag and drop your image here</p>
<p class="text-xs text-gray-400 mt-3">Supported: JPG, PNG, GIF, BMP</p>
</div>
<div id="image-info" class="mt-4 hidden">
<div class="flex justify-between mb-1">
<span class="font-medium">Original Size:</span>
<span id="original-size">-</span>
</div>
<div class="flex justify-between mb-1">
<span class="font-medium">Current Size:</span>
<span id="current-size">-</span>
</div>
<div class="flex justify-between text-secondary font-medium">
<span>Reduction:</span>
<span id="reduction-percent">-</span>
</div>
</div>
</div>
<!-- Settings Section -->
<div class="flex-1">
<div class="settings-card">
<label class="block mb-2 font-medium">Compression Quality</label>
<div class="flex items-center space-x-3">
<i class="fas fa-file-image text-gray-500"></i>
<input type="range" id="quality-range" min="10" max="95" value="75" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer accent-primary">
<i class="fas fa-file-image text-primary"></i>
</div>
<div class="flex justify-between mt-1">
<span class="text-sm text-gray-500">Smaller File</span>
<span class="text-sm text-gray-500">Better Quality</span>
</div>
<div class="text-center mt-2">
<span id="quality-value" class="font-medium text-lg">75%</span>
</div>
</div>
<div class="settings-card mt-4">
<label class="block mb-2 font-medium">Compression Format</label>
<div class="grid grid-cols-2 gap-2">
<button class="format-btn active" data-format="jpeg">JPEG</button>
<button class="format-btn" data-format="png">PNG</button>
</div>
</div>
<div class="flex gap-3 mt-6">
<button id="process-btn" class="btn-primary flex-1" disabled>
<i class="fas fa-cog mr-2"></i> Process
</button>
<button id="download-btn" class="btn-secondary flex-1" disabled>
<i class="fas fa-download mr-2"></i> Download
</button>
</div>
</div>
</div>
<!-- Preview Section -->
<div class="mt-10 grid grid-cols-1 md:grid-cols-2 gap-6">
<div class="preview-card">
<h3 class="font-medium text-gray-700 mb-2">Original Image</h3>
<div class="preview-container">
<img id="original-preview" class="max-w-full max-h-64 mx-auto">
</div>
</div>
<div class="preview-card">
<h3 class="font-medium text-gray-700 mb-2">Processed Image</h3>
<div class="preview-container">
<img id="processed-preview" class="max-w-full max-h-64 mx-auto">
</div>
</div>
</div>
</div>
</div>
<!-- Other tools would be here with similar structure -->
<!-- Resizer Tool -->
<div class="tool-section hidden" id="resizer-section">
<div class="card">
<h2 class="card-title"><i class="fas fa-expand-alt mr-2"></i> Image Resizer</h2>
<p class="text-gray-600 mb-6">Change image dimensions while preserving aspect ratio</p>
<div class="text-center py-12">
<i class="fas fa-tools text-4xl text-gray-300 mb-4"></i>
<h3 class="text-xl font-medium text-gray-600">Coming Soon</h3>
<p class="text-gray-500">Our resizer tool is currently under development</p>
</div>
</div>
</div>
<!-- Rotator Tool -->
<div class="tool-section hidden" id="rotator-section">
<div class="card">
<h2 class="card-title"><i class="fas fa-sync-alt mr-2"></i> Image Rotate & Reflect</h2>
<p class="text-gray-600 mb-6">Rotate and flip images to any orientation</p>
<div class="text-center py-12">
<i class="fas fa-tools text-4xl text-gray-300 mb-4"></i>
<h3 class="text-xl font-medium text-gray-600">Coming Soon</h3>
<p class="text-gray-500">Our rotator tool is currently under development</p>
</div>
</div>
</div>
<!-- Watermark Tool -->
<div class="tool-section hidden" id="watermark-section">
<div class="card">
<h2 class="card-title"><i class="fas fa-tint mr-2"></i> Watermark</h2>
<p class="text-gray-600 mb-6">Add text or logo watermarks to protect your images</p>
<div class="text-center py-12">
<i class="fas fa-tools text-4xl text-gray-300 mb-4"></i>
<h3 class="text-xl font-medium text-gray-600">Coming Soon</h3>
<p class="text-gray-500">Our watermark tool is currently under development</p>
</div>
</div>
</div>
</main>
<!-- Footer -->
<footer class="bg-dark text-gray-300 py-6">
<div class="container mx-auto px-4">
<div class="flex flex-col md:flex-row justify-between items-center">
<div class="mb-4 md:mb-0">
<h3 class="text-lg font-bold text-white mb-2">Image Processing Toolkit</h3>
<p class="text-sm">Powered by TensorFlow.js & HTML5</p>
</div>
<div class="flex space-x-4">
<a href="#" class="hover:text-white transition-colors">
<i class="fab fa-github text-lg"></i>
</a>
<a href="#" class="hover:text-white transition-colors">
<i class="fab fa-twitter text-lg"></i>
</a>
<a href="#" class="hover:text-white transition-colors">
<i class="fab fa-linkedin text-lg"></i>
</a>
</div>
</div>
<div class="mt-6 text-center text-sm text-gray-400">
<p>&copy; 2023 Image Processing Toolkit. All rights reserved.</p>
</div>
</div>
</footer>
</div>
<script>
// Tabs functionality
const tabs = document.querySelectorAll('[data-tab]');
const sections = document.querySelectorAll('.tool-section');
tabs.forEach(tab => {
tab.addEventListener('click', () => {
const targetId = `${tab.dataset.tab}-section`;
// Update active tab
tabs.forEach(t => t.classList.remove('active'));
tab.classList.add('active');
// Show target section
sections.forEach(section => {
section.classList.add('hidden');
});
document.getElementById(targetId).classList.remove('hidden');
});
});
// Image compressor functionality
const fileInput = document.getElementById('image-input');
const uploadArea = document.getElementById('upload-area');
const originalPreview = document.getElementById('original-preview');
const processedPreview = document.getElementById('processed-preview');
const qualityRange = document.getElementById('quality-range');
const qualityValue = document.getElementById('quality-value');
const processBtn = document.getElementById('process-btn');
const downloadBtn = document.getElementById('download-btn');
const loadingIndicator = document.getElementById('loading');
const imageInfo = document.getElementById('image-info');
const originalSize = document.getElementById('original-size');
const currentSize = document.getElementById('current-size');
const reductionPercent = document.getElementById('reduction-percent');
const formatButtons = document.querySelectorAll('.format-btn');
let originalImage = null;
let processedImageDataUrl = null;
let currentFormat = 'jpeg';
// Update quality display
qualityRange.addEventListener('input', () => {
qualityValue.textContent = `${qualityRange.value}%`;
});
// Handle file upload
fileInput.addEventListener('change', function(e) {
if (this.files && this.files[0]) {
const file = this.files[0];
// Validate file type
if (!file.type.match('image.*')) {
alert('Please select a valid image file');
return;
}
// Read the file
const reader = new FileReader();
reader.onload = function(e) {
// Load and preview original image
originalImage = new Image();
originalImage.src = e.target.result;
originalImage.onload = function() {
// Update preview
originalPreview.src = this.src;
// Show original file size
const sizeInKB = (file.size / 1024).toFixed(2);
originalSize.textContent = `${sizeInKB} KB`;
currentSize.textContent = '-';
reductionPercent.textContent = '-';
// Show image info
imageInfo.classList.remove('hidden');
// Enable process button
processBtn.disabled = false;
// Reset processed preview
processedPreview.src = '';
downloadBtn.disabled = true;
};
};
reader.readAsDataURL(file);
}
});
// Handle drag and drop
uploadArea.addEventListener('dragover', function(e) {
e.preventDefault();
this.classList.add('border-primary', 'bg-blue-50');
});
uploadArea.addEventListener('dragleave', function() {
this.classList.remove('border-primary', 'bg-blue-50');
});
uploadArea.addEventListener('drop', function(e) {
e.preventDefault();
this.classList.remove('border-primary', 'bg-blue-50');
if (e.dataTransfer.files.length) {
fileInput.files = e.dataTransfer.files;
const event = new Event('change', { bubbles: true });
fileInput.dispatchEvent(event);
}
});
// Format selection
formatButtons.forEach(button => {
button.addEventListener('click', function() {
formatButtons.forEach(b => b.classList.remove('active'));
this.classList.add('active');
currentFormat = this.dataset.format;
});
});
// Process image with TensorFlow.js
processBtn.addEventListener('click', async function() {
if (!originalImage) return;
showLoading(true);
try {
// Using TensorFlow.js for image processing
await tf.setBackend('webgl');
// Convert image to tensor
const tensor = tf.browser.fromPixels(originalImage);
// Here would be the actual TensorFlow.js compression algorithm
// For demonstration, we'll simulate compression using canvas
setTimeout(() => {
// Create an offscreen canvas
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
// Set canvas dimensions
canvas.width = originalImage.width;
canvas.height = originalImage.height;
// Draw image on canvas
ctx.drawImage(originalImage, 0, 0);
// Get the compressed data URL
const quality = parseInt(qualityRange.value) / 100;
const mimeType = currentFormat === 'png' ? 'image/png' : 'image/jpeg';
processedImageDataUrl = canvas.toDataURL(mimeType, quality);
// Update the preview
processedPreview.src = processedImageDataUrl;
// Calculate and display file size info
const base64String = processedImageDataUrl.split(',')[1];
const sizeInBytes = 4 * Math.ceil(base64String.length / 3) * 0.5624896334383812;
const sizeInKB = (sizeInBytes / 1024).toFixed(2);
// Get original size
const originalSizeValue = parseFloat(originalSize.textContent.split(' ')[0]);
// Update UI
currentSize.textContent = `${sizeInKB} KB`;
const reduction = 100 - (sizeInKB / originalSizeValue) * 100;
reductionPercent.textContent = `${reduction.toFixed(1)}%`;
// Enable download button
downloadBtn.disabled = false;
// Clean up
showLoading(false);
}, 800); // Simulated processing time
} catch (error) {
console.error('Image processing error:', error);
alert('Error processing image. Please try again.');
showLoading(false);
}
});
// Download processed image
downloadBtn.addEventListener('click', function() {
if (!processedImageDataUrl) return;
const link = document.createElement('a');
link.href = processedImageDataUrl;
// Create filename with compression info
const quality = qualityRange.value;
const fileName = `compressed-${quality}q.${currentFormat}`;
link.download = fileName;
link.click();
});
// Helper function to show/hide loading indicator
function showLoading(show) {
loadingIndicator.classList.toggle('hidden', !show);
// Disable buttons during processing
[processBtn, downloadBtn].forEach(btn => {
btn.disabled = show;
});
}
// Initialize tab - show compressor by default
document.querySelector('[data-tab="compressor"]').click();
</script>
<style>
.card {
@apply bg-white rounded-xl shadow-md overflow-hidden p-6 md:p-8;
}
.card-title {
@apply text-2xl font-bold text-primary mb-2 flex items-center;
}
.nav-tab {
@apply flex items-center px-4 py-2 rounded-lg text-white font-medium bg-white bg-opacity-20 hover:bg-opacity-30 transition-colors duration-300;
}
.nav-tab.active {
@apply bg-white bg-opacity-40 font-semibold;
}
.settings-card {
@apply bg-gray-50 rounded-lg p-4;
}
.preview-card {
@apply bg-gray-50 rounded-lg border border-gray-200 p-4;
}
.preview-container {
@apply bg-gradient-to-br from-gray-100 to-gray-200 border-2 border-dashed border-gray-300 rounded-lg flex items-center justify-center h-64 overflow-hidden;
}
.btn-primary {
@apply bg-primary hover:bg-secondary text-white font-medium py-3 px-6 rounded-lg transition-colors duration-300 flex items-center justify-center;
}
.btn-secondary {
@apply bg-gray-200 hover:bg-gray-300 text-gray-800 font-medium py-3 px-6 rounded-lg transition-colors duration-300 flex items-center justify-center;
}
.btn-primary:disabled, .btn-secondary:disabled {
@apply opacity-50 cursor-not-allowed;
}
.format-btn {
@apply bg-gray-200 text-gray-800 rounded py-2 text-center hover:bg-gray-300 transition-colors duration-200;
}
.format-btn.active {
@apply bg-primary text-white;
}
#upload-area {
transition: all 0.3s ease;
}
.tool-section {
transition: all 0.4s ease;
}
input[type="range"] {
-webkit-appearance: none;
height: 8px;
border-radius: 5px;
outline: none;
}
input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
width: 20px;
height: 20px;
border-radius: 50%;
background: #5a67d8;
cursor: pointer;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}
#loading {
transition: all 0.3s ease;
}
</style>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Saad4web/tooooly" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>