import streamlit as st import qrcode from qrcode.image.styledpil import StyledPilImage from qrcode.image.styles.moduledrawers import RoundedModuleDrawer, CircleModuleDrawer, SquareModuleDrawer from qrcode.image.styles.colorfills import SolidFillColorMask, RadialGradiantColorMask, SquareGradiantColorMask from PIL import Image, ImageDraw import io import base64 # Page configuration st.set_page_config( page_title="QR Code Generator", page_icon="📱", layout="wide", initial_sidebar_state="expanded" ) # Custom CSS for beautiful styling st.markdown(""" """, unsafe_allow_html=True) def create_qr_code(data, fill_color, back_color, border, box_size, error_correction, style_type): """Generate QR code with custom styling""" # Error correction levels error_levels = { 'L (~7%)': qrcode.constants.ERROR_CORRECT_L, 'M (~15%)': qrcode.constants.ERROR_CORRECT_M, 'Q (~25%)': qrcode.constants.ERROR_CORRECT_Q, 'H (~30%)': qrcode.constants.ERROR_CORRECT_H } # Create QR code instance qr = qrcode.QRCode( version=1, error_correction=error_levels[error_correction], box_size=box_size, border=border, ) qr.add_data(data) qr.make(fit=True) # Style configurations if style_type == "Standard": img = qr.make_image(fill_color=fill_color, back_color=back_color) elif style_type == "Rounded": img = qr.make_image( image_factory=StyledPilImage, module_drawer=RoundedModuleDrawer(), fill_color=fill_color, back_color=back_color ) elif style_type == "Circular": img = qr.make_image( image_factory=StyledPilImage, module_drawer=CircleModuleDrawer(), fill_color=fill_color, back_color=back_color ) elif style_type == "Gradient": img = qr.make_image( image_factory=StyledPilImage, color_mask=RadialGradiantColorMask(), fill_color=fill_color, back_color=back_color ) return img def get_download_link(img, filename): """Generate download link for the QR code""" buffered = io.BytesIO() img.save(buffered, format="PNG") img_str = base64.b64encode(buffered.getvalue()).decode() href = f'📥 Download QR Code' return href # Main header st.markdown("""

🎨 Beautiful QR Code Generator

Create stunning, customizable QR codes with advanced styling options

""", unsafe_allow_html=True) # Sidebar for customization with st.sidebar: st.markdown("## 🎛️ Customization Panel") # QR Code Content st.markdown('', unsafe_allow_html=True) # Style Settings st.markdown('', unsafe_allow_html=True) # Advanced Settings st.markdown('', unsafe_allow_html=True) # Main content area col1, col2 = st.columns([2, 1]) with col1: if qr_data: try: # Generate QR code qr_img = create_qr_code( qr_data, fill_color, back_color, border, box_size, error_correction, style_type ) # Display QR code st.markdown("### 📱 Your QR Code") st.image(qr_img, caption="Generated QR Code", use_container_width=True) # Download section st.markdown("""

🚀 Ready to Download!

Your QR code is ready. Click below to download it as PNG.

""", unsafe_allow_html=True) # Download button filename = f"qrcode_{content_type.lower()}.png" st.markdown(get_download_link(qr_img, filename), unsafe_allow_html=True) except Exception as e: st.error(f"Error generating QR code: {str(e)}") else: st.info("👈 Please enter content in the sidebar to generate your QR code") with col2: st.markdown("### 📋 Features") features = [ "🎨 Multiple visual styles", "🌈 Custom colors", "📱 Various content types", "⚙️ Advanced settings", "📥 Instant download", "🔧 Error correction levels" ] for feature in features: st.markdown(f'
{feature}
', unsafe_allow_html=True) st.markdown("### 💡 Tips") st.info(""" **Higher Error Correction** = More resilient to damage but larger QR code **Larger Module Size** = Easier to scan but bigger file **Good Contrast** = Better scanning reliability """) # Footer st.markdown("---") st.markdown("""

🚀 Built with Streamlit | 💝 Made with love for QR code enthusiasts

""", unsafe_allow_html=True)