V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
wencan
V2EX  ›  Linux

Linux 下有没有很方便的图片拼接软件?

  •  
  •   wencan · 26 天前 · 2006 次点击
    比如,将四张图拼成 2x2 的组合图
    或者 3 张图,右边一张,左边上下各一张
    目前每次都是上传到 canva.cn 去拼,拼图很强大,但就是还要上传

    最好还支持抠图,生成白底图、透明图
    14 条回复    2025-05-23 14:16:31 +08:00
    chiaf
        1
    chiaf  
       26 天前 via iPhone
    GIMP
    senooo
        2
    senooo  
       26 天前   ❤️ 1
    Python 大法好
    magzza
        3
    magzza  
       26 天前 via iPhone
    ImageMagick 应该可以的
    MossFox
        4
    MossFox  
       26 天前
    浏览器按理说纯本地环境也是支持这类基础图片处理的,在线工具上传图片处理属于弱化了不少客户端本来就有的能力,

    透明转白底可以直接 Canvas 一比一填个底色然后画 img ,
    基础的拼图可以手动框区域填充,也是 Canvas 那套,
    抠图可以用 https://github.com/imgly/background-removal-js 或者同类型的工具(纯本地),不过注意这个只擅长照片类型,不擅长插图类型的素材,
    某些时候如果想要转矢量,也可以用这个 https://github.com/visioncortex/vtracer
    图片处理如果有浏览器不支持的类型 (AV1, JPEG XL 之类),可以用 https://github.com/kleisauke/wasm-vips 在浏览器里面本地转换。

    这些是基建啦。如果想合在一起弄一个浏览器里跑的本地工具,会前端的可以搓一个,不熟练的但是表达能力还行的可以让大模型造一个。如果是比较常见的需求,搞不好哪里已经有人造好了但是没做过宣传的工具。
    openmynet
        5
    openmynet  
       26 天前
    https://github.com/theotherphil/imagecli 需要你自己编译到 Linux 版本,再配合 python 很容易满足你的要求
    ```python
    import os
    import subprocess
    import argparse
    from PIL import Image
    import re

    if __name__ == "__main__":

    # python jpeg_hcat.py title a.jpg b.jpg c.jpg --p="hcat"

    # 接收所有输入的参数并打印
    # print(sys.argv[1:])

    # 创建 ArgumentParser 对象
    parser = argparse.ArgumentParser(description="示例程序")

    # 添加 --type 参数
    parser.add_argument(
    "--type",
    type=str,
    default="hcat",
    choices=["hcat", "vcat", "grid"],
    help="操作类型",
    )
    # 添加 --cols 参数
    parser.add_argument(
    "--cols",
    type=int,
    default=3,
    help="列数",
    )
    # 添加 --name 参数
    parser.add_argument(
    "--name",
    type=str,
    default="image",
    help="输出文件名",
    )
    # 添加 --cols 参数
    parser.add_argument(
    "--author",
    type=str,
    default="",
    help="输出作者",
    )
    parser.add_argument("files", nargs="+", type=str, help="输入的文件列表")
    # 解析命令行参数
    args = parser.parse_args()
    process = args.type
    files = []
    name = args.name

    # 接收所有输入的参数并检查参数是否包含文件
    for file in args.files:
    # 检查文件是否存在
    temp = file.lower()
    if os.path.exists(file) and os.path.isfile(file):
    if temp.endswith(".jpg") or temp.endswith(".jpeg") or temp.endswith(".png"):
    # 将文件名转为小写后判断
    files.append(file)

    # 文件数量
    file_len = len(files)

    if file_len == 0:
    print("没有文件")
    exit(0)
    renames = []
    image = Image.open(files[0])
    width, height = image.size
    rows = file_len
    if process == "grid":
    if rows < args.cols:
    process = "hcat"
    else:
    # 计算行数
    rows_sqrt = int(rows**0.5)
    cols = rows_sqrt
    if rows_sqrt > 5:
    cols = 5
    rows = file_len // 5
    else:
    cols = rows_sqrt
    rows = rows_sqrt
    if cols * rows < file_len:
    for i in [4, 3, 2]:
    n = file_len // i
    if n * i == file_len:
    rows = n
    cols = i
    break
    process = f"grid {cols}"
    pattern = r"(\d)x(\d)"
    matrix = re.findall(pattern, args.author)
    if matrix and len(matrix) == 1:
    cols = int(matrix[0][0])
    rows = int(matrix[0][1])
    miss = cols * rows - file_len
    if miss > 0:
    # 补齐
    id = ", ".join(["id"] * file_len)
    process = f"[{id}, (new {width} {height} (255, 255, 255) > DUP {miss-1})] > grid {cols}"

    # 获取文件拓展名
    ext = os.path.splitext(files[0])[1]

    # 使用第一文件路径作为输出文件路径,并使用 name 作为文件名
    name = name + ext
    output = os.path.join(os.path.dirname(files[0]), name)
    target = f'"{output}"'
    # 将 files 格式化为字符串,以空格分隔,使用引号将文件名括起来
    quoted_files = ['"{}"'.format(file) for file in files]
    input = " ".join(quoted_files)

    # 运行命令
    cmd = f'imagecli.exe -i {input} -o {target} -p "{process} {rows}"'
    # os.system(cmd)
    result = subprocess.run(cmd, capture_output=True, text=True)
    if result.returncode == 0:
    # 打开图片
    # 1. 检查图片是否存在
    if os.path.exists(output):
    # 2. 打开图片
    os.startfile(output)

    # 接收所有输入的参数并保存到指定文件中
    out = "D:\Program Files\clawPDF\scripts\log.txt"
    with open(out, "w") as f:
    f.write(cmd + "\n")

    ```
    zuotun
        6
    zuotun  
       26 天前
    CLI FFMpeg
    GUI GIMP
    printese
        7
    printese  
       25 天前 via iPhone
    ImageMagick 下的 montage 工具貌似可以部分满足需求
    MrKrabs
        8
    MrKrabs  
       25 天前
    不如手机
    henix
        9
    henix  
       25 天前
    拼接用 ImageMagick 命令行 montage 工具
    抠图用 GIMP 相似像素选择,跟 PS 类似,要手动操作一下
    huangmingyou
        10
    huangmingyou  
       25 天前
    imagemagick , 下面是我用来生成一个 2k+4k 组合屏幕壁纸的命令。
    #!/bin/bash
    # need 2560.png and 3840.png
    convert -size 6400x2160 xc:black black.png
    convert black.png \( 2560.png -resize 2560x1440 \) -geometry +0+0 -composite result_temp.png
    convert result_temp.png \( 3840.png -resize 3840x2160 \) -geometry +2560+0 -composite final_result.png
    CFM880
        11
    CFM880  
       25 天前
    figma linux
    xy2401
        12
    xy2401  
       25 天前
    Tomatopotato
        13
    Tomatopotato  
       24 天前
    有一说一 你传到手机上用手机拼一下再传回电脑都比在 linux 上折腾来得快。
    d4eorg
        14
    d4eorg  
       14 天前
    GraphicsMagick/ImageMagick

    gm convert "$file1" "$file2" +append -quality 90 "$output"
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2683 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 11:42 · PVG 19:42 · LAX 04:42 · JFK 07:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.