
Python
<code>Python<br/>from PIL import Image def concatenate_images(image_paths, output_path): images = [Image.open(x) for x in image_paths] widths, heights = zip(*(i.size for i in images)) Total_width = sum(widths) max_height = max(heights) new_im = Image.new('RGB', (Total_width, max_height)) x_offset = 0 for im in images: new_im.paste(im, (x_offset, 0)) x_offset += im.size[0] new_im.save(output_path)
<h1>使用示例</h1>
image_paths = ['image1.jpg', 'image2.jpg', 'image3.jpg'] # 替换为你的图片路径 output_path = 'concatenated_image.jpg' # 替换为你想要保存的长图路径 concatenate_images(image_paths, output_path)</code>
这段代码会将image_paths列表中的图片从左到右拼接起来,并保存到output_path指定的位置。你可以根据需要调整代码中的参数,比如拼接方向、背景颜色等。Copyright © 2025 IZhiDa.com All Rights Reserved.
知答 版权所有 粤ICP备2023042255号