jkushwaha commited on
Commit
657c50e
·
verified ·
1 Parent(s): 52af248

Create image_display.py

Browse files
Files changed (1) hide show
  1. image_display.py +32 -0
image_display.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+
3
+ def display_side_by_side(image1_path, image2_path):
4
+ # Open images using Pillow
5
+ image1 = Image.open(image1_path)
6
+ image2 = Image.open(image2_path)
7
+
8
+ # Resize images (optional)
9
+ # Here, assuming images are of the same size
10
+ width, height = image1.size
11
+ new_width = width * 2 # Width for the side by side display
12
+ new_height = height
13
+
14
+ # Resize both images to match the new dimensions
15
+ image1 = image1.resize((new_width // 2, new_height))
16
+ image2 = image2.resize((new_width // 2, new_height))
17
+
18
+ # Create a new image with double width to place both images side by side
19
+ side_by_side = Image.new('RGB', (new_width, new_height))
20
+
21
+ # Paste the resized images into the new image
22
+ side_by_side.paste(image1, (0, 0))
23
+ side_by_side.paste(image2, (width, 0))
24
+
25
+ # Display the side by side image
26
+ side_by_side.show()
27
+
28
+ # Example usage:
29
+ if __name__ == "__main__":
30
+ image1_path = 'path_to_image1.jpg'
31
+ image2_path = 'path_to_image2.jpg'
32
+ display_side_by_side(image1_path, image2_path)