test / image_display_test.html
Mahdi Naser Moghadasi
Fix malformed image HTML generation
e9e471e
Raw History Blame Contribute Delete
6.62 kB
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Display Test - Shorter Names</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background-color: #f5f5f5;
}
.header {
text-align: center;
margin-bottom: 30px;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 20px;
border-radius: 10px;
}
.image-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.image-card {
background: white;
border-radius: 10px;
padding: 15px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
text-align: center;
}
.image-card img {
max-width: 100%;
height: auto;
border-radius: 8px;
margin-bottom: 10px;
}
.image-name {
font-weight: bold;
color: #333;
margin-bottom: 5px;
}
.image-description {
color: #666;
font-size: 14px;
}
.controls {
background: white;
padding: 20px;
border-radius: 10px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.btn {
background: #667eea;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
margin: 5px;
}
.btn:hover {
background: #5a6fd8;
}
</style>
</head>
<body>
<div class="header">
<h1>🖼️ Image Display Test</h1>
<p>Testing shorter image naming and display functionality</p>
</div>
<div class="controls">
<h3>Image Management</h3>
<button class="btn" onclick="loadImages()">Load Images</button>
<button class="btn" onclick="generateNewImage()">Generate New Image</button>
<button class="btn" onclick="clearImages()">Clear All</button>
</div>
<div id="imageContainer" class="image-grid">
<!-- Images will be loaded here -->
</div>
<script>
// Shorter image naming system
function generateShortName(topic, index = 0) {
const timestamp = Date.now().toString().slice(-6); // Last 6 digits of timestamp
const topicShort = topic.replace(/[^a-zA-Z0-9]/g, '').toLowerCase().slice(0, 8);
return `img_${topicShort}_${timestamp}_${index}`;
}
// Sample images with shorter names
const sampleImages = [
{
name: generateShortName('algebra', 0),
description: 'Algebra concepts visualization',
url: 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAwIiBoZWlnaHQ9IjMwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KICA8cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjZjBmOGZmIi8+CiAgPHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSJBcmlhbCIgZm9udC1zaXplPSIyNCIgZmlsbD0iIzMzMyIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZHk9Ii4zZW0iPkFsZ2VicmE8L3RleHQ+CiAgPHRleHQgeD0iNTAlIiB5PSI2MCUiIGZvbnQtZmFtaWx5PSJBcmlhbCIgZm9udC1zaXplPSIxNiIgZmlsbD0iIzY2NiIgdGV4dC1hbmNob3I9Im1pZGRsZSI+Q29uY2VwdHM8L3RleHQ+Cjwvc3ZnPg=='
},
{
name: generateShortName('geometry', 0),
description: 'Geometric shapes and formulas',
url: 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAwIiBoZWlnaHQ9IjMwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KICA8cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjZmZmMGYwIi8+CiAgPGNpcmNsZSBjeD0iMjAwIiBjeT0iMTUwIiByPSI1MCIgZmlsbD0iIzMzMyIgZmlsbC1vcGFjaXR5PSIwLjMiLz4KICA8cmVjdCB4PSIxNTAiIHk9IjIwMCIgd2lkdGg9IjEwMCIgaGVpZ2h0PSI1MCIgZmlsbD0iIzMzMyIgZmlsbC1vcGFjaXR5PSIwLjMiLz4KICA8dGV4dCB4PSIyMDAiIHk9IjE0MCIgZm9udC1mYW1pbHk9IkFyaWFsIiBmb250LXNpemU9IjI0IiBmaWxsPSIjMzMzIiB0ZXh0LWFuY2hvcj0ibWlkZGxlIj5HZW9tZXRyeTwvdGV4dD4KPC9zdmc+'
},
{
name: generateShortName('physics', 0),
description: 'Physics equations and diagrams',
url: 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAwIiBoZWlnaHQ9IjMwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KICA8cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjZjBmOGZmIi8+CiAgPGxpbmUgeDE9IjEwMCIgeTE9IjEwMCIgeDI9IjMwMCIgeTI9IjIwMCIgc3Ryb2tlPSIjMzMzIiBzdHJva2Utd2lkdGg9IjMiLz4KICA8Y2lyY2xlIGN4PSIxMDAiIGN5PSIxMDAiIHI9IjEwIiBmaWxsPSIjNjY2Ii8+CiAgPGNpcmNsZSBjeD0iMzAwIiBjeT0iMjAwIiByPSIxMCIgZmlsbD0iIzY2NiIvPgogIDx0ZXh0IHg9IjIwMCIgeT0iMjUwIiBmb250LWZhbWlseT0iQXJpYWwiIGZvbnQtc2l6ZT0iMjQiIGZpbGw9IiMzMzMiIHRleHQtYW5jaG9yPSJtaWRkbGUiPlBoeXNpY3M8L3RleHQ+Cjwvc3ZnPg=='
}
];
function loadImages() {
const container = document.getElementById('imageContainer');
container.innerHTML = '';
sampleImages.forEach((image, index) => {
const imageCard = document.createElement('div');
imageCard.className = 'image-card';
imageCard.innerHTML = `
<img src="${image.url}" alt="${image.description}" onerror="this.style.display='none'">
<div class="image-name">${image.name}</div>
<div class="image-description">${image.description}</div>
`;
container.appendChild(imageCard);
});
}
function generateNewImage() {
const topics = ['math', 'science', 'history', 'english', 'art'];
const randomTopic = topics[Math.floor(Math.random() * topics.length)];
const newImage = {
name: generateShortName(randomTopic, Math.floor(Math.random() * 100)),
description: `Generated image for ${randomTopic}`,
url: `https://via.placeholder.com/400x300/667eea/ffffff?text=${randomTopic.toUpperCase()}`
};
sampleImages.push(newImage);
loadImages();
}
function clearImages() {
document.getElementById('imageContainer').innerHTML = '';
}
// Load images on page load
window.onload = function() {
loadImages();
};
</script>
</body>
</html>