mirror of
https://github.com/bigbeartechworld/big-bear-scripts.git
synced 2026-07-29 00:32:35 -04:00
🧪 test(favicon-generator): Add comprehensive test suite for run.sh (#52)
* 🧪 test(favicon-generator): Add comprehensive test suite for run.sh Implement a robust test script to validate favicon generation script functionality. The test suite covers: - Handling of no arguments - Non-existent file input - ImageMagick dependency check - Full favicon generation workflow - File output verification Ensures script reliability and provides clear test coverage for different scenarios. * 🔧 fix(generate-favicons): Properly quote temp directory path Ensure the temporary directory path is correctly quoted to prevent potential shell expansion or injection issues. This change improves script safety by properly escaping the directory path in the trap command.
This commit is contained in:
1
generate-favicons/.gitignore
vendored
Normal file
1
generate-favicons/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/docs/
|
||||
46
generate-favicons/CHANGELOG.md
Normal file
46
generate-favicons/CHANGELOG.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [1.0.0] - 2025-10-24
|
||||
|
||||
### Added
|
||||
- Initial release of Big Bear Favicon Generator
|
||||
- Support for multiple input image formats (PNG, SVG, JPG, BMP, GIF, TIFF, WEBP)
|
||||
- Automatic generation of 7 favicon files:
|
||||
- favicon.ico (multi-resolution: 16x16, 32x32, 48x48)
|
||||
- favicon-16x16.png
|
||||
- favicon-32x32.png
|
||||
- apple-touch-icon.png (180x180)
|
||||
- android-chrome-192x192.png
|
||||
- android-chrome-512x512.png
|
||||
- site.webmanifest
|
||||
- Multi-resolution ICO file generation with embedded 16x16, 32x32, and 48x48 sizes
|
||||
- Web app manifest (site.webmanifest) generation
|
||||
- Non-square image handling with automatic square canvas creation
|
||||
- SVG support with high-quality 300 DPI conversion
|
||||
- Compatibility with both ImageMagick 6 and 7
|
||||
- Automatic transparent background handling
|
||||
- Comprehensive error checking and user-friendly error messages
|
||||
- Interactive prompts for edge cases (non-square images)
|
||||
- Command-line interface with input file and output directory options
|
||||
- Detailed installation instructions in output
|
||||
- Test suite (test.sh) for validating functionality
|
||||
- Comprehensive documentation:
|
||||
- README.md with quick start guide
|
||||
- docs/QUICKSTART.md for fast-track setup
|
||||
- docs/INSTALLATION.md with platform-specific instructions
|
||||
- docs/EXAMPLES.md with real-world usage examples
|
||||
- PROJECT_SUMMARY.md with technical overview
|
||||
|
||||
### Security
|
||||
- All processing happens locally - no data transmitted to external servers
|
||||
- No network requests required for operation
|
||||
|
||||
[unreleased]: https://github.com/bigbeartechworld/big-bear-scripts/compare/v1.0.0...HEAD
|
||||
[1.0.0]: https://github.com/bigbeartechworld/big-bear-scripts/releases/tag/v1.0.0
|
||||
259
generate-favicons/README.md
Normal file
259
generate-favicons/README.md
Normal file
@@ -0,0 +1,259 @@
|
||||
# Big Bear Favicon Generator 🐻❄️
|
||||
|
||||
Generate a complete set of favicons from any source image (PNG, SVG, JPG, etc.) - just like [favicon.io](https://favicon.io) but local!
|
||||
|
||||
## What This Script Does
|
||||
|
||||
This script automatically generates all the favicon files you need for modern websites and apps:
|
||||
|
||||
- **favicon.ico** - Multi-resolution ICO file (16x16, 32x32, 48x48)
|
||||
- **favicon-16x16.png** - Small favicon for browser tabs
|
||||
- **favicon-32x32.png** - Standard favicon
|
||||
- **apple-touch-icon.png** - 180x180 icon for iOS devices
|
||||
- **android-chrome-192x192.png** - Android home screen icon
|
||||
- **android-chrome-512x512.png** - High-res Android icon
|
||||
- **site.webmanifest** - Web app manifest file
|
||||
|
||||
## Prerequisites
|
||||
|
||||
**ImageMagick** must be installed on your system:
|
||||
|
||||
### Installation
|
||||
|
||||
**macOS:**
|
||||
```bash
|
||||
brew install imagemagick
|
||||
```
|
||||
|
||||
**Ubuntu/Debian:**
|
||||
```bash
|
||||
sudo apt-get update
|
||||
sudo apt-get install imagemagick
|
||||
```
|
||||
|
||||
**CentOS/RHEL:**
|
||||
```bash
|
||||
sudo yum install ImageMagick
|
||||
```
|
||||
|
||||
**Arch Linux:**
|
||||
```bash
|
||||
sudo pacman -S imagemagick
|
||||
```
|
||||
|
||||
**Windows (WSL):**
|
||||
```bash
|
||||
sudo apt-get install imagemagick
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
### Run Directly from GitHub
|
||||
|
||||
You can run the script directly without cloning the repository:
|
||||
|
||||
```bash
|
||||
bash -c "$(wget -qLO - https://raw.githubusercontent.com/bigbeartechworld/big-bear-scripts/master/generate-favicons/run.sh)" -s <input-image> <output-directory>
|
||||
```
|
||||
|
||||
Or with curl:
|
||||
|
||||
```bash
|
||||
bash -c "$(curl -fsSL https://raw.githubusercontent.com/bigbeartechworld/big-bear-scripts/master/generate-favicons/run.sh)" -s <input-image> <output-directory>
|
||||
```
|
||||
|
||||
### Basic Usage
|
||||
|
||||
After cloning or downloading the script:
|
||||
|
||||
```bash
|
||||
bash run.sh <input-image>
|
||||
```
|
||||
|
||||
This will generate all favicon files in the current directory.
|
||||
|
||||
### Specify Output Directory
|
||||
|
||||
```bash
|
||||
bash run.sh <input-image> <output-directory>
|
||||
```
|
||||
|
||||
### Examples
|
||||
|
||||
```bash
|
||||
# Generate favicons from a PNG file
|
||||
bash run.sh logo.png
|
||||
|
||||
# Generate favicons from SVG and output to a specific directory
|
||||
bash run.sh logo.svg ./public
|
||||
|
||||
# Generate favicons and output to web server directory
|
||||
bash run.sh icon.jpg /var/www/html
|
||||
```
|
||||
|
||||
## Supported Input Formats
|
||||
|
||||
- PNG
|
||||
- SVG (recommended for best quality)
|
||||
- JPG/JPEG
|
||||
- BMP
|
||||
- GIF
|
||||
- TIFF
|
||||
- WEBP
|
||||
|
||||
## Best Practices
|
||||
|
||||
### Image Requirements
|
||||
|
||||
1. **Use a square image** - The script works best with square images (e.g., 512x512, 1024x1024)
|
||||
2. **Simple designs work best** - Complex images lose detail when scaled down to 16x16
|
||||
3. **High resolution source** - Start with at least 512x512 pixels for best results
|
||||
4. **Transparent background** - Use PNG or SVG with transparent background for best results
|
||||
|
||||
### Recommended Source Image Specs
|
||||
|
||||
- **Format:** PNG or SVG
|
||||
- **Size:** 512x512 or larger
|
||||
- **Background:** Transparent
|
||||
- **Content:** Simple, recognizable icon or logo
|
||||
|
||||
## Installation on Your Website
|
||||
|
||||
After generating the favicons, follow these steps:
|
||||
|
||||
### 1. Upload Files
|
||||
|
||||
Upload all generated files to your website's root directory:
|
||||
- favicon.ico
|
||||
- favicon-16x16.png
|
||||
- favicon-32x32.png
|
||||
- apple-touch-icon.png
|
||||
- android-chrome-192x192.png
|
||||
- android-chrome-512x512.png
|
||||
- site.webmanifest
|
||||
|
||||
### 2. Add HTML Tags
|
||||
|
||||
Add these tags to the `<head>` section of your HTML:
|
||||
|
||||
```html
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
|
||||
<link rel="manifest" href="/site.webmanifest">
|
||||
```
|
||||
|
||||
### 3. Customize site.webmanifest (Optional)
|
||||
|
||||
Edit the `site.webmanifest` file to add your app's name and customize colors:
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "My Awesome App",
|
||||
"short_name": "MyApp",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/android-chrome-192x192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/android-chrome-512x512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png"
|
||||
}
|
||||
],
|
||||
"theme_color": "#2196F3",
|
||||
"background_color": "#ffffff",
|
||||
"display": "standalone"
|
||||
}
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
✅ Supports multiple input formats (PNG, SVG, JPG, etc.)
|
||||
✅ Generates all standard favicon sizes
|
||||
✅ Creates multi-resolution ICO file
|
||||
✅ Handles non-square images (with warning)
|
||||
✅ SVG support with high-quality conversion
|
||||
✅ Generates web app manifest
|
||||
✅ Works with both ImageMagick 6 and 7
|
||||
✅ Automatic transparent background handling
|
||||
✅ No internet connection required
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### "ImageMagick is not installed" Error
|
||||
|
||||
Install ImageMagick using the commands in the Prerequisites section above.
|
||||
|
||||
### "Input file not found" Error
|
||||
|
||||
Make sure the path to your image file is correct. Use absolute paths if needed:
|
||||
|
||||
```bash
|
||||
bash run.sh ~/Desktop/logo.png
|
||||
```
|
||||
|
||||
### Non-Square Image Warning
|
||||
|
||||
If your image is not square, the script will center it on a transparent square canvas. For best results, crop your image to be square before running the script.
|
||||
|
||||
### ICO File Not Working
|
||||
|
||||
Make sure you've uploaded the favicon.ico file to your website's root directory. Clear your browser cache and try accessing your site in a private/incognito window.
|
||||
|
||||
### SVG Files Appearing Small
|
||||
|
||||
The script converts SVG files at 300 DPI to maintain quality. If the output is too small, try increasing the `-density` value in the script or export your SVG to a high-resolution PNG first.
|
||||
|
||||
## Testing Your Favicons
|
||||
|
||||
After installation, test your favicons:
|
||||
|
||||
1. **Browser Tab** - Check if the favicon appears in your browser tab
|
||||
2. **Bookmarks** - Bookmark the page and check if the icon appears
|
||||
3. **iOS** - Add to home screen on iPhone/iPad
|
||||
4. **Android** - Add to home screen on Android device
|
||||
5. **Favicon Checker** - Use online tools like [Favicon Checker](https://realfavicongenerator.net/favicon_checker)
|
||||
|
||||
## Why This Script?
|
||||
|
||||
This script provides a free, open-source alternative to online favicon generators like favicon.io:
|
||||
|
||||
- ✅ **Privacy** - No need to upload your logo to third-party websites
|
||||
- ✅ **Offline** - Works without internet connection
|
||||
- ✅ **Automation** - Can be integrated into build scripts
|
||||
- ✅ **Free** - No limitations, no watermarks
|
||||
- ✅ **Customizable** - Modify the script for your specific needs
|
||||
|
||||
## Changelog
|
||||
|
||||
See [CHANGELOG.md](CHANGELOG.md) for a detailed history of changes to this project.
|
||||
|
||||
## Contributing
|
||||
|
||||
Found a bug or have a suggestion? Please open an issue on GitHub!
|
||||
|
||||
## Credits
|
||||
|
||||
Created by [BigBearTechWorld](https://github.com/BigBearTechWorld)
|
||||
|
||||
Inspired by [favicon.io](https://favicon.io) by John Sorrentino
|
||||
|
||||
## License
|
||||
|
||||
See the LICENSE file in the repository root.
|
||||
|
||||
## Support
|
||||
|
||||
If you find this script helpful, consider:
|
||||
|
||||
- ⭐ Starring the repository
|
||||
- ☕ [Buying me a tea on Ko-fi](https://ko-fi.com/bigbeartechworld)
|
||||
- 💬 Joining the [Big Bear Community](https://community.bigbeartechworld.com)
|
||||
- 📺 Subscribing to the [YouTube channel](https://youtube.com/@bigbeartechworld)
|
||||
|
||||
## Related Scripts
|
||||
|
||||
Check out other useful scripts in the [big-bear-scripts](https://github.com/bigbeartechworld/big-bear-scripts) repository!
|
||||
BIN
generate-favicons/images/logo.png
Normal file
BIN
generate-favicons/images/logo.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 130 KiB |
267
generate-favicons/run.sh
Executable file
267
generate-favicons/run.sh
Executable file
@@ -0,0 +1,267 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Function to print headers
|
||||
print_header() {
|
||||
echo "========================================="
|
||||
echo " $1"
|
||||
echo "========================================="
|
||||
}
|
||||
|
||||
# Function to print status messages
|
||||
print_status() {
|
||||
echo "✅ $1"
|
||||
}
|
||||
|
||||
# Function to print error messages
|
||||
print_error() {
|
||||
echo "❌ $1"
|
||||
}
|
||||
|
||||
# Function to print warning messages
|
||||
print_warning() {
|
||||
echo "⚠️ $1"
|
||||
}
|
||||
|
||||
# Display Welcome
|
||||
print_header "Big Bear Favicon Generator V1.0.0"
|
||||
echo "Generate favicons from any image (PNG, SVG, JPG, etc.)"
|
||||
echo ""
|
||||
echo "Here are some links:"
|
||||
echo "https://community.bigbeartechworld.com"
|
||||
echo "https://github.com/BigBearTechWorld"
|
||||
echo ""
|
||||
echo "If you would like to support me, please consider buying me a tea:"
|
||||
echo "https://ko-fi.com/bigbeartechworld"
|
||||
echo ""
|
||||
|
||||
# Check if ImageMagick is installed
|
||||
if ! command -v magick &> /dev/null && ! command -v convert &> /dev/null; then
|
||||
print_error "ImageMagick is not installed!"
|
||||
echo ""
|
||||
echo "Please install ImageMagick:"
|
||||
echo " • macOS: brew install imagemagick"
|
||||
echo " • Ubuntu/Debian: sudo apt-get install imagemagick"
|
||||
echo " • CentOS/RHEL: sudo yum install ImageMagick"
|
||||
echo " • Arch: sudo pacman -S imagemagick"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Determine which ImageMagick command to use
|
||||
if command -v magick &> /dev/null; then
|
||||
MAGICK_CMD="magick"
|
||||
print_status "Found ImageMagick 7+ (magick command)"
|
||||
else
|
||||
MAGICK_CMD="convert"
|
||||
print_status "Found ImageMagick 6 (convert command)"
|
||||
fi
|
||||
|
||||
# Check for input file
|
||||
if [ $# -eq 0 ]; then
|
||||
echo "Usage: $0 <input-image> [output-directory]"
|
||||
echo ""
|
||||
echo "Supported formats: PNG, JPG, JPEG, SVG, BMP, GIF, TIFF, WEBP"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " $0 logo.png"
|
||||
echo " $0 logo.svg ./output"
|
||||
echo " $0 ~/Desktop/icon.jpg /var/www/html"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
INPUT_FILE="$1"
|
||||
OUTPUT_DIR="${2:-.}"
|
||||
|
||||
# Check if input file exists
|
||||
if [ ! -f "$INPUT_FILE" ]; then
|
||||
print_error "Input file not found: $INPUT_FILE"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the file extension
|
||||
FILE_EXT="${INPUT_FILE##*.}"
|
||||
FILE_EXT_LOWER=$(echo "$FILE_EXT" | tr '[:upper:]' '[:lower:]')
|
||||
|
||||
# Validate file format
|
||||
SUPPORTED_FORMATS="png jpg jpeg svg bmp gif tiff tif webp"
|
||||
if [[ ! " $SUPPORTED_FORMATS " =~ " $FILE_EXT_LOWER " ]]; then
|
||||
print_error "Unsupported file format: .$FILE_EXT"
|
||||
echo "Supported formats: PNG, JPG, JPEG, SVG, BMP, GIF, TIFF, WEBP"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
print_status "Input file: $INPUT_FILE"
|
||||
print_status "Output directory: $OUTPUT_DIR"
|
||||
|
||||
# Create output directory if it doesn't exist
|
||||
mkdir -p "$OUTPUT_DIR"
|
||||
|
||||
# Temporary working directory
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
trap 'rm -rf "$TEMP_DIR"' EXIT
|
||||
|
||||
print_header "Processing Image"
|
||||
|
||||
# For SVG files, we need special handling
|
||||
if [ "$FILE_EXT_LOWER" = "svg" ]; then
|
||||
print_status "Converting SVG to PNG at high resolution..."
|
||||
# Convert SVG to high-res PNG first (1024x1024)
|
||||
if [ "$MAGICK_CMD" = "magick" ]; then
|
||||
magick -density 300 -background none "$INPUT_FILE" -resize 1024x1024 "$TEMP_DIR/source.png"
|
||||
else
|
||||
convert -density 300 -background none "$INPUT_FILE" -resize 1024x1024 "$TEMP_DIR/source.png"
|
||||
fi
|
||||
SOURCE_FILE="$TEMP_DIR/source.png"
|
||||
else
|
||||
SOURCE_FILE="$INPUT_FILE"
|
||||
fi
|
||||
|
||||
# Get image dimensions
|
||||
if [ "$MAGICK_CMD" = "magick" ]; then
|
||||
IMAGE_WIDTH=$(magick identify -format "%w" "$SOURCE_FILE" 2>/dev/null)
|
||||
IMAGE_HEIGHT=$(magick identify -format "%h" "$SOURCE_FILE" 2>/dev/null)
|
||||
else
|
||||
IMAGE_WIDTH=$(identify -format "%w" "$SOURCE_FILE" 2>/dev/null)
|
||||
IMAGE_HEIGHT=$(identify -format "%h" "$SOURCE_FILE" 2>/dev/null)
|
||||
fi
|
||||
|
||||
print_status "Source image dimensions: ${IMAGE_WIDTH}x${IMAGE_HEIGHT}"
|
||||
|
||||
# Check if image is square
|
||||
if [ "$IMAGE_WIDTH" != "$IMAGE_HEIGHT" ]; then
|
||||
print_warning "Input image is not square (${IMAGE_WIDTH}x${IMAGE_HEIGHT})"
|
||||
echo "For best results, use a square image. The image will be centered on a square canvas."
|
||||
echo ""
|
||||
read -r -p "Continue anyway? (y/N): " continue_non_square
|
||||
if [[ ! $continue_non_square =~ ^[Yy]$ ]]; then
|
||||
print_status "Cancelled by user"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Create square canvas with transparent/white background
|
||||
MAX_DIM=$((IMAGE_WIDTH > IMAGE_HEIGHT ? IMAGE_WIDTH : IMAGE_HEIGHT))
|
||||
print_status "Creating square canvas (${MAX_DIM}x${MAX_DIM})..."
|
||||
|
||||
if [ "$MAGICK_CMD" = "magick" ]; then
|
||||
magick "$SOURCE_FILE" -background none -gravity center -extent ${MAX_DIM}x${MAX_DIM} "$TEMP_DIR/square.png"
|
||||
else
|
||||
convert "$SOURCE_FILE" -background none -gravity center -extent ${MAX_DIM}x${MAX_DIM} "$TEMP_DIR/square.png"
|
||||
fi
|
||||
SOURCE_FILE="$TEMP_DIR/square.png"
|
||||
fi
|
||||
|
||||
print_header "Generating Favicon Files"
|
||||
|
||||
# Generate favicon sizes
|
||||
# Standard sizes: 16x16, 32x32, 48x48, 180x180 (Apple), 192x192, 512x512 (Android)
|
||||
|
||||
print_status "Creating favicon-16x16.png..."
|
||||
if [ "$MAGICK_CMD" = "magick" ]; then
|
||||
magick "$SOURCE_FILE" -resize 16x16 "$OUTPUT_DIR/favicon-16x16.png"
|
||||
else
|
||||
convert "$SOURCE_FILE" -resize 16x16 "$OUTPUT_DIR/favicon-16x16.png"
|
||||
fi
|
||||
|
||||
print_status "Creating favicon-32x32.png..."
|
||||
if [ "$MAGICK_CMD" = "magick" ]; then
|
||||
magick "$SOURCE_FILE" -resize 32x32 "$OUTPUT_DIR/favicon-32x32.png"
|
||||
else
|
||||
convert "$SOURCE_FILE" -resize 32x32 "$OUTPUT_DIR/favicon-32x32.png"
|
||||
fi
|
||||
|
||||
print_status "Creating apple-touch-icon.png (180x180)..."
|
||||
if [ "$MAGICK_CMD" = "magick" ]; then
|
||||
magick "$SOURCE_FILE" -resize 180x180 "$OUTPUT_DIR/apple-touch-icon.png"
|
||||
else
|
||||
convert "$SOURCE_FILE" -resize 180x180 "$OUTPUT_DIR/apple-touch-icon.png"
|
||||
fi
|
||||
|
||||
print_status "Creating android-chrome-192x192.png..."
|
||||
if [ "$MAGICK_CMD" = "magick" ]; then
|
||||
magick "$SOURCE_FILE" -resize 192x192 "$OUTPUT_DIR/android-chrome-192x192.png"
|
||||
else
|
||||
convert "$SOURCE_FILE" -resize 192x192 "$OUTPUT_DIR/android-chrome-192x192.png"
|
||||
fi
|
||||
|
||||
print_status "Creating android-chrome-512x512.png..."
|
||||
if [ "$MAGICK_CMD" = "magick" ]; then
|
||||
magick "$SOURCE_FILE" -resize 512x512 "$OUTPUT_DIR/android-chrome-512x512.png"
|
||||
else
|
||||
convert "$SOURCE_FILE" -resize 512x512 "$OUTPUT_DIR/android-chrome-512x512.png"
|
||||
fi
|
||||
|
||||
print_status "Creating multi-resolution favicon.ico (16x16, 32x32, 48x48)..."
|
||||
# Create temporary files for ICO generation
|
||||
if [ "$MAGICK_CMD" = "magick" ]; then
|
||||
magick "$SOURCE_FILE" -resize 16x16 "$TEMP_DIR/icon-16.png"
|
||||
magick "$SOURCE_FILE" -resize 32x32 "$TEMP_DIR/icon-32.png"
|
||||
magick "$SOURCE_FILE" -resize 48x48 "$TEMP_DIR/icon-48.png"
|
||||
|
||||
# Combine into ICO file
|
||||
magick "$TEMP_DIR/icon-16.png" "$TEMP_DIR/icon-32.png" "$TEMP_DIR/icon-48.png" "$OUTPUT_DIR/favicon.ico"
|
||||
else
|
||||
convert "$SOURCE_FILE" -resize 16x16 "$TEMP_DIR/icon-16.png"
|
||||
convert "$SOURCE_FILE" -resize 32x32 "$TEMP_DIR/icon-32.png"
|
||||
convert "$SOURCE_FILE" -resize 48x48 "$TEMP_DIR/icon-48.png"
|
||||
|
||||
# Combine into ICO file
|
||||
convert "$TEMP_DIR/icon-16.png" "$TEMP_DIR/icon-32.png" "$TEMP_DIR/icon-48.png" "$OUTPUT_DIR/favicon.ico"
|
||||
fi
|
||||
|
||||
print_header "Generating Web Manifest"
|
||||
|
||||
# Create site.webmanifest
|
||||
cat > "$OUTPUT_DIR/site.webmanifest" << 'EOF'
|
||||
{
|
||||
"name": "",
|
||||
"short_name": "",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/android-chrome-192x192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/android-chrome-512x512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png"
|
||||
}
|
||||
],
|
||||
"theme_color": "#ffffff",
|
||||
"background_color": "#ffffff",
|
||||
"display": "standalone"
|
||||
}
|
||||
EOF
|
||||
|
||||
print_status "Created site.webmanifest"
|
||||
|
||||
print_header "Installation Instructions"
|
||||
|
||||
echo "Files generated successfully in: $OUTPUT_DIR"
|
||||
echo ""
|
||||
echo "Generated files:"
|
||||
echo " • favicon.ico (16x16, 32x32, 48x48)"
|
||||
echo " • favicon-16x16.png"
|
||||
echo " • favicon-32x32.png"
|
||||
echo " • apple-touch-icon.png (180x180)"
|
||||
echo " • android-chrome-192x192.png"
|
||||
echo " • android-chrome-512x512.png"
|
||||
echo " • site.webmanifest"
|
||||
echo ""
|
||||
echo "To use these favicons on your website:"
|
||||
echo ""
|
||||
echo "1. Upload all files to your website's root directory"
|
||||
echo ""
|
||||
echo "2. Add these tags to your HTML <head> section:"
|
||||
echo ""
|
||||
cat << 'EOF'
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
|
||||
<link rel="manifest" href="/site.webmanifest">
|
||||
EOF
|
||||
echo ""
|
||||
echo "3. (Optional) Edit site.webmanifest to add your app name and colors"
|
||||
echo ""
|
||||
|
||||
print_header "Generation Complete!"
|
||||
print_status "All favicons generated successfully!"
|
||||
165
generate-favicons/test.sh
Executable file
165
generate-favicons/test.sh
Executable file
@@ -0,0 +1,165 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Test script for favicon generator
|
||||
# This script tests the various features and edge cases
|
||||
|
||||
echo "========================================="
|
||||
echo " Favicon Generator - Test Suite"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
|
||||
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
FAVICON_SCRIPT="$SCRIPT_DIR/run.sh"
|
||||
|
||||
# Check if script exists
|
||||
if [ ! -f "$FAVICON_SCRIPT" ]; then
|
||||
echo "❌ Error: run.sh not found in $SCRIPT_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "Testing script: $FAVICON_SCRIPT"
|
||||
echo ""
|
||||
|
||||
# Test 1: No arguments (should show help)
|
||||
echo "Test 1: Running without arguments (expect help message)..."
|
||||
echo "-----------------------------------------------------------"
|
||||
bash "$FAVICON_SCRIPT"
|
||||
EXIT_CODE=$?
|
||||
if [ $EXIT_CODE -eq 1 ]; then
|
||||
echo "✅ Test 1 passed: Script correctly shows error when no arguments provided"
|
||||
else
|
||||
echo "❌ Test 1 failed: Unexpected exit code $EXIT_CODE"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Test 2: Non-existent file
|
||||
echo "Test 2: Running with non-existent file (expect error)..."
|
||||
echo "-----------------------------------------------------------"
|
||||
bash "$FAVICON_SCRIPT" "nonexistent.png" 2>&1 | head -20
|
||||
EXIT_CODE=$?
|
||||
if [ $EXIT_CODE -eq 1 ]; then
|
||||
echo "✅ Test 2 passed: Script correctly handles non-existent file"
|
||||
else
|
||||
echo "❌ Test 2 failed: Unexpected exit code $EXIT_CODE"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Test 3: Check if ImageMagick is installed
|
||||
echo "Test 3: Checking ImageMagick installation..."
|
||||
echo "-----------------------------------------------------------"
|
||||
if command -v magick &> /dev/null; then
|
||||
echo "✅ ImageMagick 7+ found (magick command)"
|
||||
IMAGEMAGICK_INSTALLED=true
|
||||
MAGICK_VERSION=$(magick --version | head -1)
|
||||
echo " Version: $MAGICK_VERSION"
|
||||
elif command -v convert &> /dev/null; then
|
||||
echo "✅ ImageMagick 6 found (convert command)"
|
||||
IMAGEMAGICK_INSTALLED=true
|
||||
CONVERT_VERSION=$(convert --version | head -1)
|
||||
echo " Version: $CONVERT_VERSION"
|
||||
else
|
||||
echo "❌ ImageMagick is not installed"
|
||||
echo " Install with: brew install imagemagick (macOS)"
|
||||
echo " sudo apt-get install imagemagick (Ubuntu/Debian)"
|
||||
IMAGEMAGICK_INSTALLED=false
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# If ImageMagick is installed, run full test
|
||||
if [ "$IMAGEMAGICK_INSTALLED" = true ]; then
|
||||
echo "========================================="
|
||||
echo " Running Full Functionality Tests"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
|
||||
# Test 4: Generate favicons with test image
|
||||
if [ -f "$SCRIPT_DIR/images/logo.png" ]; then
|
||||
echo "Test 4: Generating favicons from test image..."
|
||||
echo "-----------------------------------------------------------"
|
||||
|
||||
# Create temp directory for output
|
||||
TEST_OUTPUT=$(mktemp -d)
|
||||
echo "Output directory: $TEST_OUTPUT"
|
||||
echo ""
|
||||
|
||||
# Run the script
|
||||
bash "$FAVICON_SCRIPT" "$SCRIPT_DIR/images/logo.png" "$TEST_OUTPUT"
|
||||
EXIT_CODE=$?
|
||||
|
||||
if [ $EXIT_CODE -eq 0 ]; then
|
||||
echo ""
|
||||
echo "Checking generated files..."
|
||||
|
||||
EXPECTED_FILES=(
|
||||
"favicon.ico"
|
||||
"favicon-16x16.png"
|
||||
"favicon-32x32.png"
|
||||
"apple-touch-icon.png"
|
||||
"android-chrome-192x192.png"
|
||||
"android-chrome-512x512.png"
|
||||
"site.webmanifest"
|
||||
)
|
||||
|
||||
ALL_FILES_PRESENT=true
|
||||
for file in "${EXPECTED_FILES[@]}"; do
|
||||
if [ -f "$TEST_OUTPUT/$file" ]; then
|
||||
FILE_SIZE=$(ls -lh "$TEST_OUTPUT/$file" | awk '{print $5}')
|
||||
echo " ✅ $file ($FILE_SIZE)"
|
||||
else
|
||||
echo " ❌ $file (missing)"
|
||||
ALL_FILES_PRESENT=false
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$ALL_FILES_PRESENT" = true ]; then
|
||||
echo ""
|
||||
echo "✅ Test 4 passed: All favicon files generated successfully"
|
||||
echo ""
|
||||
echo "Generated files are in: $TEST_OUTPUT"
|
||||
echo "You can inspect them manually if needed"
|
||||
echo ""
|
||||
|
||||
# Verify ICO file structure
|
||||
if command -v magick &> /dev/null; then
|
||||
echo "Verifying ICO file structure..."
|
||||
magick identify "$TEST_OUTPUT/favicon.ico" 2>&1 | grep -E "\.ico\[" || true
|
||||
fi
|
||||
else
|
||||
echo ""
|
||||
echo "❌ Test 4 failed: Some files missing"
|
||||
fi
|
||||
else
|
||||
echo "❌ Test 4 failed: Script exited with code $EXIT_CODE"
|
||||
fi
|
||||
|
||||
# Clean up option
|
||||
echo ""
|
||||
read -r -p "Delete test output directory? (y/N): " cleanup
|
||||
if [[ $cleanup =~ ^[Yy]$ ]]; then
|
||||
rm -rf "$TEST_OUTPUT"
|
||||
echo "✅ Test output cleaned up"
|
||||
else
|
||||
echo "ℹ️ Test output kept at: $TEST_OUTPUT"
|
||||
fi
|
||||
|
||||
else
|
||||
echo "⚠️ Test image not found: $SCRIPT_DIR/images/logo.png"
|
||||
echo " Skipping full functionality test"
|
||||
fi
|
||||
else
|
||||
echo "========================================="
|
||||
echo " Skipping Full Tests"
|
||||
echo "========================================="
|
||||
echo ""
|
||||
echo "To run full tests, install ImageMagick:"
|
||||
echo ""
|
||||
echo "macOS: brew install imagemagick"
|
||||
echo "Ubuntu/Debian: sudo apt-get install imagemagick"
|
||||
echo "CentOS/RHEL: sudo yum install ImageMagick"
|
||||
echo "Arch Linux: sudo pacman -S imagemagick"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "========================================="
|
||||
echo " Test Suite Complete"
|
||||
echo "========================================="
|
||||
Reference in New Issue
Block a user