After watching a Youtube by the very respected Dave on a new command line shell called Warp, I gave its go. After describing a task to be done it built the commands needed for that task and executed them. In this case I asked it to "create a page of thumbnails images from a directory of pictures". As it progressed it provided explanations and checked before running any actual commands. The task was achieved by generating a command script incorporating the subtasks to be done. The script was left behind and can be adapted and deployed in other similar situations.
Very impressive I can see we will have to explore this tool further.
Available on Mac, Windows, Linux from Warp.dev
The script created .. Might need to add .png and parameterise a few things before redeployment
#!/bin/bash
# Create thumbnails directory if it doesn't exist
mkdir -p CEP_Thumbnails
# Remove any existing thumbnails to start fresh
rm -f CEP_Thumbnails/*.jpg CEP_Thumbnails/*.jpeg
# Counter for thumbnails
count=0
# Process all JPG and JPEG files
for img in CEP_AllPics/*.jpg CEP_AllPics/*.jpeg CEP_AllPics/*.JPG CEP_AllPics/*.JPEG; do
# Check if file exists (to handle case when no matches are found)
if [ -f "$img" ]; then
# Extract filename without path
filename=$(basename "$img")
echo "Creating thumbnail for $filename"
# Create thumbnail using sips
sips --resampleWidth 150 "$img" --out "CEP_Thumbnails/$filename"
# Increment counter
((count++))
fi
done
echo "Created $count thumbnails"
# Generate HTML file
cat > thumbnails.html << EOF
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image Thumbnails</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f5f5f5;
}
h1 {
text-align: center;
color: #333;
}
.thumbnail-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
gap: 15px;
padding: 20px;
}
.thumbnail-container {
background: white;
box-shadow: 0 2px 5px rgba(0,0,0,0.1);
padding: 10px;
border-radius: 5px;
text-align: center;
transition: transform 0.3s ease;
}
.thumbnail-container:hover {
transform: scale(1.05);
}
.thumbnail-container img {
max-width: 150px;
max-height: 150px;
display: block;
margin: 0 auto 8px auto;
}
.thumbnail-container p {
margin: 5px 0 0 0;
font-size: 12px;
color: #666;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.timestamp {
text-align: center;
margin-top: 30px;
color: #777;
font-size: 14px;
}
</style>
</head>
<body>
<h1>Image Thumbnails</h1>
<div class="thumbnail-grid">
EOF
# Add each thumbnail to the HTML
for thumb in CEP_Thumbnails/*.jpg CEP_Thumbnails/*.jpeg CEP_Thumbnails/*.JPG CEP_Thumbnails/*.JPEG; do
if [ -f "$thumb" ]; then
filename=$(basename "$thumb")
echo " <div class=\"thumbnail-container\">" >> thumbnails.html
echo " <a href=\"CEP_AllPics/$filename\" target=\"_blank\">" >> thumbnails.html
echo " <img src=\"$thumb\" alt=\"$filename\">" >> thumbnails.html
echo " <p>$filename</p>" >> thumbnails.html
echo " </a>" >> thumbnails.html
echo " </div>" >> thumbnails.html
fi
done
# Close the HTML file
cat >> thumbnails.html << EOF
</div>
<div class="timestamp">
Generated on $(date)
</div>
</body>
</html>
EOF
echo "HTML gallery created: thumbnails.html"
echo "Open this file in your web browser to view the thumbnails."
# Make the script executable
chmod +x create_thumbnails.sh
No comments:
Post a Comment