190 lines
5.5 KiB
Markdown
190 lines
5.5 KiB
Markdown
# QR Code Manager
|
|
|
|
A comprehensive Python web application for creating, customizing, and managing QR codes. This application provides functionality similar to popular QR code generation websites with additional features for local management.
|
|
|
|
## Features
|
|
|
|
### QR Code Types Supported
|
|
- **Text**: Plain text QR codes
|
|
- **URL/Website**: Direct links to websites
|
|
- **WiFi**: WiFi network connection details
|
|
- **Email**: Pre-filled email composition
|
|
- **Phone**: Direct phone number dialing
|
|
- **SMS**: Pre-filled SMS messages
|
|
- **vCard**: Digital contact cards
|
|
|
|
### Customization Options
|
|
- **Colors**: Customizable foreground and background colors
|
|
- **Styles**: Square, rounded, or circular module styles
|
|
- **Size**: Adjustable module size (5-15px per module)
|
|
- **Logo**: Option to add custom logos to QR codes
|
|
|
|
### Management Features
|
|
- **Preview**: Real-time preview of generated QR codes
|
|
- **Download**: Export QR codes as PNG images
|
|
- **History**: View and manage previously generated QR codes
|
|
- **Delete**: Remove unwanted QR codes
|
|
- **Copy**: Copy QR codes to clipboard
|
|
|
|
## Installation
|
|
|
|
1. **Clone or navigate to the project directory**:
|
|
```bash
|
|
cd /home/pi/Desktop/qr-code_manager
|
|
```
|
|
|
|
2. **Install dependencies**:
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
Or if using the virtual environment that was created:
|
|
```bash
|
|
/home/pi/Desktop/qr-code_manager/.venv/bin/pip install -r requirements.txt
|
|
```
|
|
|
|
## Usage
|
|
|
|
1. **Start the server**:
|
|
```bash
|
|
python app.py
|
|
```
|
|
|
|
Or with the virtual environment:
|
|
```bash
|
|
/home/pi/Desktop/qr-code_manager/.venv/bin/python app.py
|
|
```
|
|
|
|
2. **Access the application**:
|
|
Open your web browser and navigate to `http://localhost:5000`
|
|
|
|
3. **Create QR codes**:
|
|
- Select the type of QR code you want to create
|
|
- Fill in the required information
|
|
- Customize the appearance (colors, style, size)
|
|
- Click "Generate QR Code"
|
|
- Download or copy your QR code
|
|
|
|
## API Endpoints
|
|
|
|
The application provides a RESTful API for programmatic access:
|
|
|
|
### Generate QR Code
|
|
- **POST** `/api/generate`
|
|
- **Body**: JSON with QR code parameters
|
|
- **Response**: Generated QR code data and download URL
|
|
|
|
### Download QR Code
|
|
- **GET** `/api/download/<qr_id>`
|
|
- **Response**: PNG image file
|
|
|
|
### List QR Codes
|
|
- **GET** `/api/qr_codes`
|
|
- **Response**: JSON array of all generated QR codes
|
|
|
|
### Get QR Code Details
|
|
- **GET** `/api/qr_codes/<qr_id>`
|
|
- **Response**: JSON with QR code details
|
|
|
|
### Delete QR Code
|
|
- **DELETE** `/api/qr_codes/<qr_id>`
|
|
- **Response**: Success/error status
|
|
|
|
### Upload Logo
|
|
- **POST** `/api/upload_logo`
|
|
- **Body**: Multipart form with logo file
|
|
- **Response**: Logo path for use in QR generation
|
|
|
|
## Example API Usage
|
|
|
|
### Generate a URL QR Code
|
|
```bash
|
|
curl -X POST http://localhost:5000/api/generate \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"type": "url",
|
|
"content": "https://github.com",
|
|
"foreground_color": "#000000",
|
|
"background_color": "#FFFFFF",
|
|
"style": "square",
|
|
"size": 10
|
|
}'
|
|
```
|
|
|
|
### Generate a WiFi QR Code
|
|
```bash
|
|
curl -X POST http://localhost:5000/api/generate \
|
|
-H "Content-Type: application/json" \
|
|
-d '{
|
|
"type": "wifi",
|
|
"wifi": {
|
|
"ssid": "MyNetwork",
|
|
"password": "MyPassword",
|
|
"security": "WPA"
|
|
},
|
|
"foreground_color": "#0066cc",
|
|
"background_color": "#ffffff"
|
|
}'
|
|
```
|
|
|
|
## File Structure
|
|
|
|
```
|
|
qr-code_manager/
|
|
├── app.py # Main Flask application
|
|
├── requirements.txt # Python dependencies
|
|
├── README.md # This file
|
|
├── templates/
|
|
│ └── index.html # Web interface
|
|
├── static/
|
|
│ ├── qr_codes/ # Generated QR code images
|
|
│ └── logos/ # Uploaded logo files
|
|
└── .venv/ # Virtual environment (if created)
|
|
```
|
|
|
|
## Dependencies
|
|
|
|
- **Flask**: Web framework
|
|
- **qrcode[pil]**: QR code generation with PIL support
|
|
- **Pillow**: Image processing
|
|
- **flask-cors**: Cross-Origin Resource Sharing support
|
|
- **python-dotenv**: Environment variable management
|
|
|
|
## Security Considerations
|
|
|
|
- The application runs in debug mode by default - disable for production
|
|
- File uploads are stored locally - implement proper validation and storage limits
|
|
- QR codes are stored in memory - consider using a database for persistence
|
|
- The server accepts connections from all interfaces (0.0.0.0) - restrict for production
|
|
|
|
## Customization
|
|
|
|
### Adding New QR Code Types
|
|
1. Add the new type to the HTML select options
|
|
2. Create corresponding form fields in the HTML
|
|
3. Add processing logic in the `/api/generate` endpoint
|
|
4. Update the JavaScript to handle the new type
|
|
|
|
### Styling
|
|
The application uses embedded CSS for easy customization. Modify the `<style>` section in `templates/index.html` to change the appearance.
|
|
|
|
### Storage
|
|
Currently uses in-memory storage. To persist data:
|
|
1. Install a database library (SQLite, PostgreSQL, etc.)
|
|
2. Replace the `qr_codes_db` dictionary with database operations
|
|
3. Add database initialization code
|
|
|
|
## Troubleshooting
|
|
|
|
### Common Issues
|
|
1. **Port already in use**: Change the port in `app.py` or stop the conflicting service
|
|
2. **Permission errors**: Ensure the application has write permissions to the static directories
|
|
3. **Missing dependencies**: Reinstall requirements with `pip install -r requirements.txt`
|
|
|
|
### Debug Mode
|
|
The application runs in debug mode, which provides detailed error messages and auto-reload functionality. Disable for production by setting `debug=False` in the `app.run()` call.
|
|
|
|
## License
|
|
|
|
This project is open source. Feel free to modify and distribute according to your needs.
|