Skip to content

QR Code Generator Service #174 #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions QR CODE GENERATOR/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Barcode Generator

This project is a web-based application that allows users to generate barcodes and QR codes. The application is built using Flask (Python) for the backend, and HTML/CSS for the frontend. Users can input text and select a barcode type to generate and download the corresponding barcode or QR code image.

<img src="brgen.png" alt="Screenshot of the Barcode Generator" width="1200">

## Features

- **Generate Barcodes**: Supports different types of barcodes including QR Code, Code 128, EAN-13, and UPC-A.
- **Customizable Colors**: Users can select the color of the barcode or QR code.
- **Image Download**: The generated barcode or QR code can be downloaded directly as a PNG image.

## Technologies Used

- **Python**: Backend logic and barcode generation using the Flask framework.
- **Flask**: Web framework used to serve the application.
- **HTML/CSS**: Frontend interface design.
- **qrcode**: Python library for generating QR codes.
- **python-barcode**: Python library for generating barcodes.

## Installation and Setup

### Prerequisites

- Python 3.x
- pip (Python package manager)

### Installation Steps

1. **Clone the Repository**:
```bash
git clone https://github.com/yourusername/barcode-generator.git
cd barcode-generator
2. **Install Dependencies: Install the required Python packages using pip:**

```bash
pip install flask qrcode[pil] python-barcode Pillow
3. **Run the Application: Start the Flask server:**

```bash
python app.py
4. **Access the Application:** Open your web browser and navigate to http://127.0.0.1:5000/ to use the barcode generator.

## Usage

- **Input the Code:** Enter the text or code that you want to generate as a barcode or QR code.
- **Select Barcode Type:** Choose from QR Code, Code 128, EAN-13, or UPC-A.
- **Choose a Color:** Pick a color for the barcode or QR code using the color picker.
- **Generate and Download:** Click the "Generate Barcode" button. The barcode or QR code will be generated and downloaded as a PNG image.
## File Structure
```plaintext
barcode-generator/
├── templates/
│ └── index.html # HTML file for the frontend interface
├── app.py # Main application file containing Flask routes and logic
└── README.md # This README file
```
## Troubleshooting
- **Missing Libraries:** Ensure all required Python packages are installed using pip install -r requirements.txt.
- **Port Issues:** If the default port 5000 is already in use, change the port in app.py by updating the app.run() function.
## Contributing
Contributions are welcome! If you find any issues or have ideas for improvements, feel free to create an issue or submit a pull request.
44 changes: 44 additions & 0 deletions QR CODE GENERATOR/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from flask import Flask, render_template, request, send_file
import barcode
from barcode.writer import ImageWriter
from io import BytesIO
import qrcode

app = Flask(__name__)

@app.route('/')
def index():
return render_template('index.html')

@app.route('/generate', methods=['POST'])
def generate_barcode():
code = request.form['code']
barcode_type = request.form['barcode_type']
color = request.form.get('color', 'black')

if barcode_type == "qrcode":
qr = qrcode.QRCode(
version=1,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=4,
)
qr.add_data(code)
qr.make(fit=True)
img = qr.make_image(fill_color=color, back_color="white")
buffer = BytesIO()
img.save(buffer, format="PNG")
buffer.seek(0)
return send_file(buffer, mimetype='image/png', as_attachment=True, download_name='qrcode.png')
else:
barcode_format = barcode.get_barcode_class(barcode_type)
generated_barcode = barcode_format(code, writer=ImageWriter())
options = {'foreground': color}
buffer = BytesIO()
generated_barcode.write(buffer, options=options)
buffer.seek(0)

return send_file(buffer, mimetype='image/png', as_attachment=True, download_name='barcode.png')

if __name__ == '__main__':
app.run(debug=True)
75 changes: 75 additions & 0 deletions QR CODE GENERATOR/static/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

body {
background: linear-gradient(135deg, #000000, #6a0dad, #000000);
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
margin: 0;
font-family: 'Press Start 2P', cursive;
}

.container {
width: 700px;
height: 500px;
margin: 0 auto;
padding: 20px;
background: linear-gradient(135deg, #000000, #6a0dad, #000000);
box-shadow: 5px 5px 17px 17px rgba(255, 255, 255, 0.5);
border-radius: 12px;
color: #ffffff;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
font-family: 'Press Start 2P', cursive;
}

h1 {
color: #ffffff;
text-align: center;
margin-bottom: 20px;
font-family: 'Press Start 2P', cursive;
}

.form-label {
font-weight: bold;
color: #ffffff;
margin-bottom: 10px;
font-family: 'Press Start 2P', cursive;
}

input[type="color"] {
width: 100%;
height: 40px;
border-radius: 5px;
padding: 0;
cursor: pointer;
border: none;
background: transparent;
box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}

input[type="color"]::-webkit-color-swatch-wrapper {
padding: 0;
border-radius: 5px;
}

input[type="color"]::-webkit-color-swatch {
border: none;
border-radius: 5px;
}

.btn-primary {
background-color: #6a0dad;
border-color: #6a0dad;
margin-top: 20px;
border-width: 2px;
font-family: 'Press Start 2P', cursive;
}

.btn-primary:hover {
background-color: #5c0b8e;
border-color: #5c0b8e;
}
38 changes: 38 additions & 0 deletions QR CODE GENERATOR/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Barcode and QR Code Generator</title>
<link rel="stylesheet" href="/QR CODE GENERATOR/static/styles.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>
<script src="/static/scripts.js" defer></script>
</head>
<body>
<div class="container">
<h1 class="text-center mt-5">Barcode & QR Code Generator</h1>
<form action="/generate" method="POST" class="mt-4">
<div class="mb-3">
<label for="code" class="form-label">Enter Code:</label>
<input type="text" id="code" name="code" class="form-control" required>
</div>
<div class="mb-3">
<label for="barcode_type" class="form-label">Select Barcode Type:</label>
<select id="barcode_type" name="barcode_type" class="form-select" required>
<option value="code128">Code128</option>
<option value="ean13">EAN-13</option>
<option value="upca">UPC-A</option>
<option value="qrcode">QR Code</option>
</select>
</div>
<div class="mb-3">
<label for="color" class="form-label">Select Barcode Color:</label>
<input type="color" id="color" name="color" class="form-control" value="#000000">
</div>
<button type="submit" class="btn btn-primary w-100">Generate</button>
</form>
</div>
</body>
</html>