👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!
I am trying to horizontally combine some JPEG images in Python.
Problem
I have 3 images - each is 148 x 95 - see attached. I just made 3 copies of the same image - that is why they are the same.
My attempt
I am trying to horizontally join them using the following code:
import sys
from PIL import Image
list_im = ["Test1.jpg","Test2.jpg","Test3.jpg"]
# creates a new empty image, RGB mode, and size 444 by 95
new_im = Image.new("RGB", (444,95))
for elem in list_im:
for i in xrange(0,444,95):
im=Image.open(elem)
new_im.paste(im, (i,0))
new_im.save("test.jpg")
However, this is producing the output attached as test.jpg
.
Question
Is there a way to horizontally concatenate these images such that the sub-images in test.jpg do not have an extra partial image showing?
Additional Information
I am looking for a way to horizontally concatenate n images. I would like to use this code generally so I would prefer to:
- not to hard-code image dimensions, if possible
- specify dimensions in one line so that they can be easily changed
👻 Read also: what is the best laptop for engineering students?
We hope this article has helped you to resolve the problem. Apart from Combine several images horizontally with Python, check other ast Python module-related topics.
Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.
By the way, this material is also available in other languages:
- Italiano Combine several images horizontally with Python
- Deutsch Combine several images horizontally with Python
- Français Combine several images horizontally with Python
- Español Combine several images horizontally with Python
- Türk Combine several images horizontally with Python
- Русский Combine several images horizontally with Python
- Português Combine several images horizontally with Python
- Polski Combine several images horizontally with Python
- Nederlandse Combine several images horizontally with Python
- 中文 Combine several images horizontally with Python
- 한국어 Combine several images horizontally with Python
- 日本語 Combine several images horizontally with Python
- हिन्दी Combine several images horizontally with Python
Tallinn | 2023-03-29
Maybe there are another answers? What Combine several images horizontally with Python exactly means?. Will use it in my bachelor thesis
Massachussetts | 2023-03-29
Maybe there are another answers? What Combine several images horizontally with Python exactly means?. Checked yesterday, it works!
Abu Dhabi | 2023-03-29
re Python module is always a bit confusing 😭 Combine several images horizontally with Python is not the only problem I encountered. I just hope that will not emerge anymore