import streamlit as st import cv2 from PIL import Image import io import numpy as np from passport_img import merge_all def grayscale_image(image): # Convert the image to grayscale gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) return gray st.title('📷Passport Photo Maker📷') st.write("Made with ❤️ by Mainak") def main(): # st.title("Grayscale Image Converter") # File uploader uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"]) size = st.selectbox('Select Size',('3X4','3.5X4.5','2.0X2.5')) size = int(''.join(i for i in size if not i in ['X','.'])) if size==3545: num_img = st.slider('Number of Image', 0, 36, 6) elif size==34: num_img = st.slider('Number of Image', 0, 49, 7) else: num_img = st.slider('Number of Image', 0, 100, 10) if uploaded_file is not None: if st.button('Make'): # Read the image image = Image.open(uploaded_file) img_array = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR) # st.image(image, caption='Original Image', use_column_width=True) # Convert to grayscale gray_image = merge_all(num_img,img_array,size) gray_image = cv2.cvtColor(np.array(gray_image), cv2.COLOR_BGR2RGB) pil_image = Image.fromarray(gray_image) st.image(pil_image, caption='Passport Image', use_column_width=True) # Create a download link for the grayscale image buffered = io.BytesIO() pil_image.save(buffered, format="PNG") download_btn = st.download_button( label='Download Image', data=buffered.getvalue(), file_name='passport_image.png', mime='image/png' ) if __name__ == '__main__': main()