EDIT:
If you would have images in folder static then you could send only list with filenames and use for-loop in template to generate tags like <img src="/static/1.jpg">
@app.route('/')
def hello_world():
#filenames = os.listdir('static')
filenames = ['1.jpg', '2.jpg']
return render_template('index.html', filenames=filenames)
template
{% for name in filenames %}
<img src="/static/{{ name }}">
{% endfor %}
If you need to use base64 then you have to use for-loop in Flask
@app.route('/')
def hello_world():
#filenames = os.listdir('D:\\1111')
#filenames = [os.path.join('D:\\1111', name) for name in filenames]
filenames = ['D:\\1111\\1.jpg', 'D:\\1111\\2.jpg']
images = []
for img_path in filenames:
img_stream = return_img_stream(img_path)
images.append(img_stream)
return render_template('index.html', images=images)
template
{% for img in images %}
<img src="data:image/jpeg;base64, {{ img }}">
{% endfor %}
EDIT:
If you would merge all images to create single image then you would need modules like pillow or opencv to convert jpg to raw image, merge them, convert it back to single jpg.
EDIT:
If you want to add images with some text (ie. with filename) then you have to create list with pairs (image, text) and {% for img, txt in images %} and put text using {{ txt }}
@app.route('/')
def hello_world():
#filenames = os.listdir('D:\\1111')
#filenames = [os.path.join('D:\\1111', name) for name in filenames]
filenames = ['D:\\1111\\1.jpg', 'D:\\1111\\2.jpg']
images = []
for img_path in filenames:
img_stream = return_img_stream(img_path)
images.append( [img_stream, img_path ])
return render_template('index.html', images=images)
template
{% for img, txt in images %}
filename: {{ txt }}<br/>
<img src="data:image/jpeg;base64, {{ img }}">
{% endfor %}
But if you mean text on image then it may need pillow to edit images and put text on images.
Or you will have to learn CSS for positioning elements in HTML.
<style>
div.image { ... }
div.image span { ... }
</style>
{% for img, txt in images %}
<div class="image">
<span>filename: {{ txt }}</span>
<img src="data:image/jpeg;base64, {{ img }}">
<div>
{% endfor %}
staticthen you could send only list with filenames and usefor-loop in template to generate like<img src="/static/1.jpg">for-loop inhello_worldto create list with manyimg_stream- and later you will needfor-loop in template to display it