File size: 24,591 Bytes
b6ea795 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 | <!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>© 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> |