Spaces:
				
			
			
	
			
			
					
		Running
		
	
	
	
			
			
	
	
	
	
		
		
					
		Running
		
	cropping
Browse files
    	
        app.py
    CHANGED
    
    | @@ -50,13 +50,25 @@ def overlay_png_on_side_by_side_images( | |
| 50 | 
             
                img2 = insect_image_path.convert("RGBA")
         | 
| 51 | 
             
                png_img = Image.open(overlay_image_path).convert("RGBA")
         | 
| 52 | 
             
                min_height = 3600
         | 
|  | |
| 53 | 
             
                img1_hpercent = min_height / float(img1.size[1])
         | 
| 54 | 
             
                img1_wsize = int((float(img1.size[0]) * float(img1_hpercent)))
         | 
| 55 | 
             
                img2_hpercent = min_height / float(img2.size[1])
         | 
| 56 | 
             
                img2_wsize = int((float(img2.size[0]) * float(img2_hpercent)))
         | 
|  | |
| 57 | 
             
                img1 = img1.resize((img1_wsize, min_height), Image.LANCZOS)
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 58 | 
             
                img2 = img2.resize((img2_wsize, min_height), Image.LANCZOS)
         | 
| 59 | 
            -
                 | 
|  | |
|  | |
|  | |
|  | |
| 60 | 
             
                # Create a blank canvas for the combined image
         | 
| 61 |  | 
| 62 | 
             
                combined_image = Image.new(
         | 
| @@ -64,8 +76,8 @@ def overlay_png_on_side_by_side_images( | |
| 64 | 
             
                )  # Transparent background
         | 
| 65 |  | 
| 66 | 
             
                # Paste images side by side
         | 
| 67 | 
            -
                combined_image.paste( | 
| 68 | 
            -
                combined_image.paste( | 
| 69 |  | 
| 70 | 
             
                # Resize PNG to fit within the combined image dimensions if necessary, or to a desired size
         | 
| 71 | 
             
                # For simplicity, let's resize the PNG to a quarter of the combined image's width, maintaining aspect ratio
         | 
|  | |
| 50 | 
             
                img2 = insect_image_path.convert("RGBA")
         | 
| 51 | 
             
                png_img = Image.open(overlay_image_path).convert("RGBA")
         | 
| 52 | 
             
                min_height = 3600
         | 
| 53 | 
            +
                new_width = 2700
         | 
| 54 | 
             
                img1_hpercent = min_height / float(img1.size[1])
         | 
| 55 | 
             
                img1_wsize = int((float(img1.size[0]) * float(img1_hpercent)))
         | 
| 56 | 
             
                img2_hpercent = min_height / float(img2.size[1])
         | 
| 57 | 
             
                img2_wsize = int((float(img2.size[0]) * float(img2_hpercent)))
         | 
| 58 | 
            +
             | 
| 59 | 
             
                img1 = img1.resize((img1_wsize, min_height), Image.LANCZOS)
         | 
| 60 | 
            +
                im1_left = (img1_wsize - new_width) / 2
         | 
| 61 | 
            +
                im1_right = (img1_wsize + new_width) / 2
         | 
| 62 | 
            +
                top = 0
         | 
| 63 | 
            +
                bottom = min_height
         | 
| 64 | 
            +
                cropped_img1 = img1.crop((int(im1_left), int(top), int(im1_right), int(bottom)))
         | 
| 65 | 
            +
             | 
| 66 | 
             
                img2 = img2.resize((img2_wsize, min_height), Image.LANCZOS)
         | 
| 67 | 
            +
                im2_left = (img2_wsize - new_width) / 2
         | 
| 68 | 
            +
                im2_right = (img2_wsize + new_width) / 2
         | 
| 69 | 
            +
                cropped_img2 = img2.crop((int(im2_left), int(top), int(im2_right), int(bottom)))
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                combined_width = 5400
         | 
| 72 | 
             
                # Create a blank canvas for the combined image
         | 
| 73 |  | 
| 74 | 
             
                combined_image = Image.new(
         | 
|  | |
| 76 | 
             
                )  # Transparent background
         | 
| 77 |  | 
| 78 | 
             
                # Paste images side by side
         | 
| 79 | 
            +
                combined_image.paste(cropped_img1, (0, 0))
         | 
| 80 | 
            +
                combined_image.paste(cropped_img2, (cropped_img1.width, 0))
         | 
| 81 |  | 
| 82 | 
             
                # Resize PNG to fit within the combined image dimensions if necessary, or to a desired size
         | 
| 83 | 
             
                # For simplicity, let's resize the PNG to a quarter of the combined image's width, maintaining aspect ratio
         | 
 
			
