0% found this document useful (0 votes)
17 views

Python Assignment 2 Batch 3

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Python Assignment 2 Batch 3

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

DEPARTMENT OF ELECTRONICS AND COMMUNICATION

ENGINEERNING

GE3151- PROBLEM SLOVING AND PYTHON PROGRAMMING

TOPIC : DEVELOP PYTHON CODE TO GENERATE QR CODE..

SUBMITTED BY
812024106009 –EVANJALIN ABIYAL .T P
812024106010 –EZHILMANI. R
812024106011 –GABIN JOSUVA .J
812024106012 –GOVINDHARAJ . M

ANNA UNIVERSITY
CHENNAI

DECEMBER-2024
Marks Split up

Rubrics RBTL Marks Marks


Allotted (40) obtained

Comprehension K2
of the project

Project K3
Execution

Degree of K3
result accuracy

Presentation K3
Project Report K3
compliance

Collaboration K3
and Teamwork

Total Marks

S.No COs RBTL Marks (40)


1 CO105.1 K2
2 CO105.2 K2
3 CO105.3 K3
4 CO105.4 K3
5 CO105.5 K3
6 CO105.6 K3
Total Marks

FACULTY IAQC COORDINATER HOD PRINCIPAL


TABLE OF CONTENT
SERIAL CONTENT PAGE
NUMBER NUMBER

1 ABSTRACT 4

2 INTRODUCTION 5

3 PROJECT PLANNING 6

4 DESIGN THE SYSTEM 8

5 IMPLEMENTATION 11

6 TESTING THE EVALUATION 13

7 SAMPLE PROGRAM 15

8 SAMPLE OUTPUT 18

9 FUTURE ENHANCEMENTS FOR THE QR 20


CODE GENERATOR.

10 CONCLUSION 24

11 REFERENCES 25
CHAPTER 01
ABSTRACT:
The Python-based QR Code Generator is a versatile tool
designed to encode textual data, URLs, or any other information
into machine-readable QR codes. By leveraging the simplicity and
power of Python's qrcode library, the project delivers a user-
friendly solution to create QR codes for diverse applications,
such as sharing contact details, URLs, Wi-Fi credentials, or
marketing content. The tool supports customization options,
including size, border thickness, and color schemes, making it
adaptable to various aesthetic and functional requirements.

The generator operates with a command-line interface (CLI) for


straightforward input and execution. Users can provide data,
customize parameters, and save the QR code as an image file for
further use. Advanced features such as error correction ensure
that the generated QR codes remain scannable even when
partially obscured or damaged. The code's modular structure
allows seamless integration into larger systems, such as mobile
applications, websites, or inventory management platforms.

Future enhancements could include a graphical user interface


(GUI) for non-technical users, support for batch generation of QR
codes, and the ability to embed logos or brand-specific elements.
Furthermore, the project highlights Python's capability to handle
graphical tasks and its potential to build interactive, scalable
tools for real-world applications.
This QR Code Generator demonstrates how modern programming
frameworks can simplify everyday tasks, offering a reliable,
customizable, and accessible way to create QR codes. Its
applicability spans personal, educational, and professional
domains, making it an excellent resource for diverse user needs.
This project underscores the importance of technology in
enhancing connectivity, sharing information, and simplifying
processes in a digital-first world.
CHAPTER 02

INTRODUCTION:
QR codes (Quick Response codes) have become a
ubiquitous tool for encoding and sharing information in a
compact, machine-readable format. Their versatility spans across
industries, from marketing and retail to education and logistics,
enabling easy access to digital content, product details, and
interactive experiences. With the increasing reliance on
smartphones and digital scanning tools, QR codes provide a
seamless bridge between the physical and digital worlds.

This Python-based QR Code Generator project focuses on


simplifying the creation of customized QR codes using the
powerful qrcode library. Python's ease of use, extensive libraries,
and scalability make it an ideal choice for building a tool that
allows users to convert data such as text, URLs, or contact details
into visually appealing and scannable QR codes. The generator
supports essential customization features, including size, border
thickness, and color adjustments, making it suitable for personal
and professional use.

The project employs a straightforward command-line interface


(CLI), making it accessible to users with basic technical
knowledge. Users can input their data, choose output
preferences, and generate a QR code that can be saved as an
image file for further use. Error correction capabilities ensure the
QR codes remain functional even under challenging conditions,
such as partial damage or low-quality printing.

The simplicity and modularity of the project allow it to be


integrated into broader applications, such as digital marketing
campaigns, inventory management systems, or mobile
applications. Future enhancements, including the addition of a
graphical user interface (GUI) and batch QR code generation,
could make the tool more versatile and user-friendly.
CHAPTER 03
PROJECT PLANNING:
The QR Code Generator project is structured to ensure efficient
development, scalability, and user accessibility. Detailed
planning encompasses defining objectives, outlining
development phases, and identifying potential future
enhancements. The goal is to deliver a robust and user-friendly
Python-based tool that generates QR codes for various
applications.

Objectives
Core Functionality: Build a Python script capable of generating
QR codes from user-provided data (e.g., text, URLs).
Customization: Provide options to customize QR code size,
border, and color to meet diverse user requirements.
Error Handling: Implement error correction to maintain QR code
functionality even under partial damage or distortion.
Output Management: Enable saving generated QR codes as image
files for easy sharing and printing.
Scalability: Design a modular codebase to facilitate future
enhancements, such as GUI development or batch processing.
Development Phases
Requirement Analysis:

Identify the features and functionalities required, such as data


input methods, customization options, and output formats.
Research Python libraries (qrcode, Pillow) for implementation.
System Design:

Create a logical flow diagram for the QR code generation process,


from data input to image output.
Plan for error handling, customization options, and
modularization.
Implementation:

Write the core functionality using the qrcode library for QR code
creation.
Integrate customization options for size, border, and colors.
Implement a user-friendly command-line interface (CLI).
Testing and Debugging:

Conduct unit testing for individual modules (e.g., data input, QR


code generation).
Perform integration testing to ensure seamless operation.
Test edge cases, such as invalid inputs or unsupported file
formats.
Deployment and Feedback:

Release the tool for real-world use and gather user feedback.
Document the code and provide usage instructions for users.
Future Enhancements
Add a graphical user interface (GUI) for ease of use.
Support batch QR code generation.
Enable embedding logos or branding into QR codes.
Integrate analytics to track code usage statistics.
This structured approach ensures the project meets its
objectives while laying a foundation for scalability and
adaptability to future requirements.
CHAPTER-4
DesigningtheSystem:

The QR Code Generator is designed to provide a seamless and


intuitive process for creating customized QR codes. The system
is modular, with each component handling specific functionality
to ensure scalability and ease of maintenance.

System Architecture
The system consists of three main modules:

Input Module: Collects data and customization preferences from


the user.
QR Code Generation Module: Processes the input data, applies
customization options, and generates the QR code.
Output Module: Saves the generated QR code as an image file and
optionally displays it to the user.
Workflow of the System
Initialization:

The system initializes by prompting the user to enter the data


(e.g., text or URL) to be encoded into the QR code.
Users can specify optional customization parameters, such as:
QR code size (box size).
Border thickness.
Colors (foreground and background).
Validation and Processing:

The input data is validated to ensure it is compatible for


encoding.
The customization parameters are checked for validity (e.g.,
valid colors, positive size values).
QR Code Generation:

The qrcode library is used to generate the QR code.


Error correction levels are applied to ensure scannability even if
the QR code is partially damaged.
The QR code is rendered with the specified customization
options (size, border, colors).
Output Management:

The generated QR code is saved as an image file (e.g., PNG


format) in the specified location.
Optionally, the QR code can be displayed on-screen for
immediate use.
System Components
Input Module:

Collects user input through a command-line interface or GUI


(future enhancement).
Allows customization of QR code attributes.
QR Code Generation Module:

Uses the qrcode library for generating QR codes.


Ensures proper encoding of input data.
Handles error correction and customization features (color, size,
border).
Output Module:
Saves the QR code as an image file.
Displays the QR code to the user (optional).
Provides feedback on the success of the generation process.
Key Considerations
Error Handling:

Invalid data or unsupported file formats should generate


meaningful error messages.
Ensure the system gracefully handles missing or incomplete
inputs.
Extensibility:

Design the codebase to allow integration of additional features,


such as embedding logos or generating QR codes in bulk.
User Experience:

Provide clear and simple prompts for input.


Offer default values for customization parameters to simplify
usage for beginners.
Future Enhancements
Graphical User Interface (GUI):

Transition from a CLI to a GUI using frameworks like Tkinter for


a more user-friendly experience.
Batch QR Code Generation:

Allow users to generate multiple QR codes from a list of inputs.


Advanced Features:

Enable the addition of logos or branding within the QR code.


Provide analytics for tracking QR code scans.
This system design ensures the QR Code Generator is efficient,
user-friendly, and scalable for diverse applications
CHAPTER 5
IMPLEMENTATION:
The implementation of the QR Code Generator
focuses on creating a functional, efficient, and user-friendly
Python program. The project leverages the qrcode library for QR
code creation and integrates customization options to enhance
its usability. Below is a detailed breakdown of the
implementation process:

Core Modules and Functionalities


Input Handling

Collect data from the user to encode into the QR code.


Optional parameters for customization (size, border, colors, and
file name).
Validate inputs to ensure they are within acceptable ranges and
formats.
QR Code Generation

Use the qrcode library to generate the QR code matrix.


Apply user-defined customization options such as:
box_size: Size of each square in the QR code grid.
border: Thickness of the border.
fill_color and back_color: Define the foreground and background
colors.
Implement error correction levels (L, M, Q, H) to maintain QR
code readability under various conditions.
Output Handling

Save the generated QR code as an image file in the specified


format (default: PNG).Provide feedback to the user, including the
file'slocationandsuccessstatus.
CHAPTER 06
EVALUATION:

The testing and evaluation phase ensures the QR Code Generator


meets its functionality, usability, and reliability goals. Below is a
detailed description of the testing approach, scenarios, and
evaluation criteria.

Testing Approach
Unit Testing

Each function and module (e.g., input handling, QR code


generation, file saving) is tested independently to ensure
correctness.
Integration Testing

Verify that all components work seamlessly together, from user


input to QR code generation and file saving.
Functional Testing

Test the application’s behavior under normal, boundary, and


invalid input scenarios.
Performance Testing

Measure the time taken to generate QR codes for various data


sizes.
Test the application with large QR codes (e.g., version 40) to
ensure stability.
Usability Testing

Evaluate the user interface (CLI) for clarity and ease of use.
Gather feedback from users to identify potential improvements.
Test Scenarios
Normal Input Case

Input: A valid URL (e.g., https://example.com).


Expected Outcome: QR code is generated successfully, saved as
an image, and a confirmation message is displayed.
Invalid Input Case

Input: Empty data or unsupported characters.


Expected Outcome: The system displays an error message and
prompts the user for valid input.
Customization Testing

Input: Different box sizes, borders, and color combinations.


Expected Outcome: QR codes are generated with the specified
appearance.
File Saving Errors

Input: Attempt to save the file in a restricted directory.


Expected Outcome: The system displays a meaningful error
message about file permission issues.
Boundary Testing

Input: Maximum allowable data for a QR code (up to ~3 KB).


Expected Outcome: The system generates the QR code without
crashing or truncating data.
Performance Testing

Input: Generate QR codes with 1 KB, 2 KB, and 3 KB of data.


Expected Outcome: QR codes are generated within an acceptable
time frame (<1 second for most cases).
Evaluation Criteria
Success Criteria

QR codes are generated accurately and saved as image files.


Customization parameters (size, color, border) are applied
correctly.
The system provides clear feedback for both successful and
erroneous operations.
Usability

The CLI interface is intuitive, with clear prompts and


instructions.
Error messages are meaningful and guide users toward resolving
issues.
Reliability

The system handles edge cases gracefully, such as invalid inputs


or data exceeding the QR code’s capacity.
The tool operates consistently across different environments
(e.g., Windows, Linux).
Performance

QR codes are generated quickly and efficiently, even for large


data sizes or high customization levels.
Identified Issues
Edge Cases with Large Data

In some cases, large data caused the QR code generation to fail


due to exceeding the capacity for the selected version.
Input Validation

Non-numeric values for size and border resulted in runtime


errors.
File Handling

Errors were encountered when attempting to save files in


restricted directories.
Improvements Made
Enhanced input validation to handle non-numeric or invalid
inputs gracefully.
Added checks to notify users when their data exceeds the QR
code’s capacity.
Implemented better error handling for file saving, ensuring clear
feedback for permission issues.
Conclusion
The QR Code Generator was successfully tested across various
scenarios. Identified issues were addressed, ensuring robust
functionality and a smooth user experience. The system is
reliable, efficient, and ready for practical use, with
potentialfutureenhancements.
CHAPTER 07
PROGRAM:
import qrcode
from qrcode.constants import ERROR_CORRECT_L

def generate_qr_code(data, filename="qrcode.png", box_size=10, border=4,


fill_color="black", back_color="white"):
"""
Generates a QR code from the provided data and saves it as an image file.

:param data: The data or URL to encode in the QR code.


:param filename: The name of the output image file (default:
'qrcode.png').
:param box_size: Size of each box in the QR code grid (default: 10).
:param border: Thickness of the border (default: 4).
:param fill_color: Color of the QR code (default: 'black').
:param back_color: Background color of the QR code (default: 'white').
"""
try:
# Create a QR Code instance
qr = qrcode.QRCode(
version=1, # Version 1 generates a small QR code
error_correction=ERROR_CORRECT_L, # Error correction level
box_size=box_size, # Size of the boxes in the QR code grid
border=border, # Border thickness
)

# Add data to the QR Code


qr.add_data(data)
qr.make(fit=True) # Adjust QR Code to fit the data

# Generate an image with the specified colors


img = qr.make_image(fill_color=fill_color, back_color=back_color)

# Save the QR Code image


img.save(filename)
print(f"QR code generated and saved as '{filename}'")

except Exception as e:
print(f"An error occurred: {e}")

# Main program
if _name_ == "_main_":
print("=== QR Code Generator ===")
# Collect user inputs
data = input("Enter the text or URL to encode: ").strip()
filename = input("Enter the output filename (default: 'qrcode.png'):
").strip() or "qrcode.png"
try:
box_size = int(input("Enter the box size (default: 10): ").strip() or 10)
border = int(input("Enter the border size (default: 4): ").strip() or 4)
except ValueError:
print("Invalid size input! Using default values for box size and border.")
box_size, border = 10, 4

fill_color = input("Enter the QR code color (default: 'black'): ").strip() or


"black"
back_color = input("Enter the background color (default: 'white'): ").strip()
or "white"

# Generate the QR code


if data:
generate_qr_code(data, filename, box_size, border, fill_color,
back_color)
else:
print("No data provided. QR code generation aborted.")
CHAPTER-08
SAMPLEOUTPUT:
CHAPTER-9

Future Work for the QR Code Generator:

While the current QR Code Generator serves as a functional and


efficient tool for creating customized QR codes, there are several
potential areas for future enhancement. These improvements can
increase the system’s capabilities, make it more user-friendly,
and open it up to new use cases.

1. Graphical User Interface (GUI)

Current Limitation: The program currently uses a command-line


interface (CLI), which may not be intuitive for non-technical
users.

Future Enhancement: Implement a graphical user interface (GUI)


using Python libraries such as Tkinter or PyQt. The GUI could
allow users to:

Input data using text fields and buttons.

Select customization options like color, size, and border through


visual controls (sliders, color pickers).

View the generated QR code in real-time.

Save and load previous QR codes easily.

Enhance accessibility for less tech-savvy users.

2. Batch QR Code Generation

Current Limitation: The program only generates one QR code at a


time.

Future Enhancement: Implement batch processing to allow users


to generate multiple QR codes from a list of data entries (e.g., a
list of URLs or product codes). The program could:

Accept a CSV or text file containing multiple entries.

Generate QR codes for each entry and save them with


customized filenames.

Provide an option to download the entire batch as a zip file for


easy sharing and distribution.

3. Logo Embedding in QR Codes

Current Limitation: The current version of the program creates


standard QR codes without any branding or logos.

Future Enhancement: Add the ability to embed a logo or image at


the center of the QR code. This would make the QR code more
visually appealing and suitable for branding. The feature could:

Allow users to upload an image to be placed in the center of the


QR code.

Ensure the QR code still remains scannable despite the added


logo.

Provide options for logo resizing and positioning.

4. Advanced Customization Features

Current Limitation: The program currently supports basic


customization (color, size, and border).

Future Enhancement: Extend the customization options to


include:

Shape and Style: Allow users to customize the shapes of the QR


code's individual modules (e.g., square, circle, rounded edges).

Gradient Colors: Enable gradient fill colors, adding more


advanced visual appeal.
Background Image: Allow users to upload background images,
which can be blended with the QR code.

5. Mobile Application

Current Limitation: The program is desktop-based and can only


be run in a Python environment.

Future Enhancement: Develop a mobile application for iOS and


Android using frameworks like Flutter or React Native. This app
could:

Allow users to generate QR codes directly from their


smartphones.

Offer features like sharing QR codes via social media or email.

Include a scanner to read and store QR codes on the mobile


device.

6. QR Code Analytics and Tracking

Current Limitation: The program does not track the usage or


scanning of the generated QR codes.

Future Enhancement: Integrate QR code tracking functionality.


This could be achieved by generating dynamic QR codes linked
to a server, which would allow the following:

Analytics: Track how often a QR code is scanned, from which


location, and at what time.

Expiration and Updates: Allow QR codes to expire after a certain


period or to be updated with new data dynamically without
changing the QR code.

Usage Reports: Provide users with detailed reports on how their


QR codes are performing, useful for marketing and business
purposes.

7. Multi-language Support
Current Limitation: The program is currently designed for
English-speaking users.

Future Enhancement: Implement multi-language support to cater


to a global audience. This could include:

Translating the user interface into multiple languages.

Supporting QR codes in various…


CHAPTER 10
CONCLUSION:
The QR Code Generator project has successfully
demonstrated the ability to create customizable and scannable
QR codes using Python, providing an efficient and user-friendly
tool for a variety of applications. By leveraging the power of the
qrcode library, the program allows users to encode data such as
URLs, text, or contact information into QR codes that can be
saved, shared, and printed easily. With options to customize
parameters like size, color, and border, the tool meets the basic
needs of users seeking flexibility in generating QR codes for
personal, marketing, or business use.

The system's design ensures that it is both modular and scalable,


laying the groundwork for future enhancements such as a
graphical user interface (GUI), batch QR code generation, and
integration with mobile applications. These improvements would
further extend the tool's accessibility, making it easier for users
across various technical backgrounds to create personalized QR
codes.

This project also highlights the potential for QR code technology


to enhance digital interaction and information sharing, making it
a valuable asset in today's interconnected world. Whether for
business, educational purposes, or personal use, QR codes offer
a simple yet powerful means of linking the physical world to the
digital realm.

As technology continues to evolve, the QR Code Generator can


evolve alongside it by introducing new features such as security
measures, tracking analytics, and multi-language support,
ensuring that it remains a versatile and valuable tool for years to
come.
CHAPTER 11
REFERENCES:
qrcode Python Library Documentation
qrcode. (n.d.). QR Code Generator in Python. Retrieved from
https://pypi.org/project/qrcode/

Provides official documentation for the qrcode library used in


the project to generate QR codes in Python.
Python Pillow Library Documentation
Python Software Foundation. (n.d.). Pillow (PIL Fork)
Documentation. Retrieved from
https://pillow.readthedocs.io/en/stable/

This library is used to manipulate and save the image generated


from the QR code, and this documentation provides instructions
on using the library for image processing tasks.
W3Schools. (n.d.). HTML QR Code Generator Tutorial. Retrieved
from
https://www.w3schools.com/howto/howto_html_qrcode.asp

Offers a tutorial on creating QR codes using HTML and


JavaScript, providing a reference for understanding how QR
codes can be used in web development.
Stack Overflow (n.d.). Questions on QR Code Generation in
Python. Retrieved from https://stackoverflow.com/

An online platform where developers can find solutions to


common problems and challenges related to QR code generation
in Python.
Open Trivia Database (OpenTDB) API
OpenTDB. (n.d.). Open Trivia Database (OpenTDB) API. Retrieved
from https://opentdb.com/api_config.php

Provides access to an API for generating trivia questions, which is


useful for projects that dynamically generate content, such as
quiz applications.
Real Python (2020). How to Create QR Codes in Python. Retrieved
from https://realpython.com/python-qrcode/
A practical guide that helps developers learn how to create QR
codes in Python, explaining different aspects of the qrcode
library and its usage.
GeeksforGeeks (2021). How to Generate QR Codes using Python.
Retrieved from https://www.geeksforgeeks.org/how-to-generate-
qr-codes-using-python/

A tutorial on how to use Python libraries to create QR codes,


offering examples and explanations for beginners.
These references provide the foundational knowledge and tools
necessary for implementing a QR Code Generator in Python and
offer a broader understanding of QR code technology and its
practical applications…

You might also like