A Python script that downloads images from URLs and organizes them locally. Built with Ubuntu principles in mind: Community, Respect, Sharing, and Practicality.
- Easy to use: Simple command-line interface with clear prompts
- Smart filename handling: Extracts filenames from URLs or generates timestamped ones
- Robust error handling: Gracefully handles network issues, HTTP errors, and file system problems
- Auto-organization: Creates and manages a dedicated "Fetched_Images" directory
- Multi-download support: Download multiple images in a single session
- Input validation: Checks URLs and provides helpful feedback
- Python 3.6 or higher
requestslibrary
- Clone or download this script
- Install the required dependency:
pip install requests
-
Run the script:
python image_downloader.py
-
Enter an image URL when prompted:
Enter image URL (or 'quit' to exit): https://example.com/image.jpg -
The script will:
- Create a "Fetched_Images" directory if it doesn't exist
- Download the image
- Save it with an appropriate filename
- Show progress and success messages
-
Continue downloading more images or type 'quit' to exit
your-project/
├── image_downloader.py
├── Fetched_Images/
│ ├── image1.jpg
│ ├── photo_1234567890.png
│ └── downloaded_image.gif
└── README.md
The script handles various error scenarios gracefully:
- Connection timeouts: When the server takes too long to respond
- Network errors: When there's no internet connection
- HTTP errors: 404 (Not Found), 403 (Forbidden), etc.
- File system errors: Permission issues or insufficient disk space
- Invalid URLs: Non-HTTP URLs or malformed addresses
requests: For HTTP requests and downloading imagesos: For file system operationsurllib.parse: For URL parsingtime: For generating unique filenames
get_filename_from_url(): Extracts or generates appropriate filenamesdownload_image(): Main download logic with error handlingmain(): User interface and program flow
==================================================
🖼️ Simple Image Downloader
Connecting communities through shared images
==================================================
Enter image URL (or 'quit' to exit): https://example.com/photo.jpg
✓ Directory 'Fetched_Images' ready
Connecting to: https://example.com/photo.jpg
✓ Image saved successfully as: Fetched_Images/photo.jpg
✓ File size: 245760 bytes
Download another image? (y/n): n
Thanks for using Image Downloader! 👋
"ModuleNotFoundError: No module named 'requests'"
- Install requests:
pip install requests
"Permission denied" error
- Check that you have write permissions in the current directory
- Try running from a different location
"Connection timed out" error
- Check your internet connection
- Try a different image URL
- Some servers may be slow or blocking automated requests
Images not downloading
- Verify the URL points to an actual image file
- Some websites may prevent direct image downloads
- Try copying the direct image URL (right-click → "Copy image address")