diff --git a/Beginner_Projects/Bar-Code-Generator/README.md b/Beginner_Projects/Bar-Code-Generator/README.md new file mode 100644 index 0000000000..1ce4cfbde6 --- /dev/null +++ b/Beginner_Projects/Bar-Code-Generator/README.md @@ -0,0 +1,24 @@ +## Barcode Generator +### ๐ŸŽฏ Goal +The goal of this project is to create a barcode generator using Streamlit. The application allows users to generate EAN-13, EAN-8, and UPCA barcodes based on a user-provided numeric code, and provides the ability to download the generated barcode image. + +### ๐Ÿงพ Description +This project is a barcode generator built with Streamlit, providing an easy-to-use interface for generating barcodes. Users can select from multiple barcode formats (EAN-13, EAN-8, UPCA), input the appropriate numeric code, and generate a barcode image. The generated barcode is displayed and can be downloaded as a PNG file. + +### ๐Ÿงฎ What I had done! +Developed a Streamlit interface for selecting barcode types and entering barcode numbers. +Validated the input based on the selected barcode format. +Generated and displayed barcodes using the python-barcode library. +Added functionality for users to download the generated barcode image. +### ๐Ÿ“š Libraries Needed +Streamlit - For building the user interface. +python-barcode - To generate the barcodes. +base64 - For encoding the barcode image to display and download in the Streamlit app. +### ๐Ÿ“ข Conclusion +The barcode generator offers a simple and effective way for users to generate and download barcodes in various formats. The app handles input validation and provides a clean interface for creating barcodes, making it a useful tool for generating barcodes on demand. + + +**Akarsh Ghildyal** +[GitHub](https://github.com/AkarshGhildyal) | [LinkedIn](https://www.linkedin.com/in/akarsh-ghildyal/) + + diff --git a/Beginner_Projects/Bar-Code-Generator/barCodeGenerator.py b/Beginner_Projects/Bar-Code-Generator/barCodeGenerator.py new file mode 100644 index 0000000000..ce2608865e --- /dev/null +++ b/Beginner_Projects/Bar-Code-Generator/barCodeGenerator.py @@ -0,0 +1,96 @@ +from barcode.writer import ImageWriter +from barcode import EAN13, EAN8, UPCA +import streamlit as st +import base64 +import os + +# Set barcode type +BARCODE_TYPE = {"EAN-13": [13, EAN13], "EAN-8": [8, EAN8], "UPCA": [12, UPCA]} + +def barCodeGenerator(): + st.markdown( + """ +

+ BAR CODE GENERATOR๐Ÿ“Š +

+ """, + unsafe_allow_html=True, + ) + + box = st.container() # To keep everything inside one container + with box: + option = st.radio( + "Select type of Barcode", ["EAN-13", "EAN-8", "UPCA"], horizontal=True + ) + num = st.text_input( + "Enter barcode number", + value="", + max_chars=BARCODE_TYPE[option][0], + placeholder=f"Enter {BARCODE_TYPE[option][0]} digits long barcode number", + ) + button_div = st.empty() # So that when Generate Barcode is pressed, it will be replaced by Reset button + + with button_div: + if st.button("Generate barcode"): + generate(num, box, option) + st.button("Reset barcode") # Resets everything + + +def generate(num, box, option): + with box: + if len(num) != BARCODE_TYPE[option][0] or not num.isnumeric(): + st.warning( + f"Please enter a valid {option} barcode of {BARCODE_TYPE[option][0]} digits!!" + ) + else: + # Path for the image + image_path = "assets/barcode" + + # Create the 'assets' directory if it doesn't exist + if not os.path.exists('assets'): + os.makedirs('assets') + + # Generate the barcode and save it + my_code = BARCODE_TYPE[option][1](num, writer=ImageWriter()) + my_code.save(image_path) + + # Open the saved image and encode it for display + with open(f"{image_path}.png", "rb") as file: + image_data = file.read() + + encoded_image = base64.b64encode(image_data).decode() + + # Display the barcode image and download button + st.markdown( + f""" + +
+ Your Image +
+ + + +
+ """, + unsafe_allow_html=True, + ) + +barCodeGenerator() diff --git a/Beginner_Projects/Bar-Code-Generator/requirements.txt b/Beginner_Projects/Bar-Code-Generator/requirements.txt new file mode 100644 index 0000000000..cf9f6decfb --- /dev/null +++ b/Beginner_Projects/Bar-Code-Generator/requirements.txt @@ -0,0 +1,4 @@ +streamlit==1.26.0 +python-barcode==0.14.0 +Pillow==10.0.1 +base64==1.1.0 \ No newline at end of file diff --git a/Repo-structure.md b/Repo-structure.md index 631d603b5b..3e67bca283 100644 --- a/Repo-structure.md +++ b/Repo-structure.md @@ -82,6 +82,10 @@ โ”‚ โ”œโ”€โ”€ README.md โ”‚ โ””โ”€โ”€ requirements.txt โ”œโ”€โ”€ Beginner_Projects +โ”‚ โ”œโ”€โ”€ Bar-Code-Generator +โ”‚ โ”‚ โ”œโ”€โ”€ README.md +โ”‚ โ”‚ โ”œโ”€โ”€ barCodeGenerator.py +โ”‚ โ”‚ โ””โ”€โ”€ requirements.txt โ”‚ โ”œโ”€โ”€ Calculator_App โ”‚ โ”‚ โ”œโ”€โ”€ README.md โ”‚ โ”‚ โ””โ”€โ”€ main.py diff --git a/repo_structure.txt b/repo_structure.txt index 7707c472d6..bc2671b6af 100644 --- a/repo_structure.txt +++ b/repo_structure.txt @@ -80,6 +80,10 @@ โ”‚ โ”œโ”€โ”€ README.md โ”‚ โ””โ”€โ”€ requirements.txt โ”œโ”€โ”€ Beginner_Projects +โ”‚ โ”œโ”€โ”€ Bar-Code-Generator +โ”‚ โ”‚ โ”œโ”€โ”€ README.md +โ”‚ โ”‚ โ”œโ”€โ”€ barCodeGenerator.py +โ”‚ โ”‚ โ””โ”€โ”€ requirements.txt โ”‚ โ”œโ”€โ”€ Calculator_App โ”‚ โ”‚ โ”œโ”€โ”€ README.md โ”‚ โ”‚ โ””โ”€โ”€ main.py