吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1976|回复: 19
收起左侧

[其他原创] 敲走硬币--长图删掉不要的部分 上下自动拼接

  [复制链接]
joody 发表于 2026-5-10 21:12
本帖最后由 joody 于 2026-5-11 10:06 编辑

使用场景:有很多产品图片,大部分平台都要求单个图片是正方形的,如果想拼成一个长图作为详情页或者方便发给客户,需要考虑删掉空白的 部分,但是一张张的处理麻烦,处理了之后,还得再保持一套文件;所以我先把用faststoneviewer 选择正方形图片按alt+t拼成长图,然后用这个html工具,切掉不要的部分,有点像在桌子上用尺子敲走硬币的游戏。最后只保留结果就行了。

11楼提醒 fsc就可以做到,亲测可行,感谢!如下
2026-05-11_100237.jpg

下面的内容可以沉了。

敲掉它.jpg
720-2026-05-10_210757.jpg



[HTML] 纯文本查看 复制代码
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>删除图片选区,上下自动拼接</title>
    <style>
        * {margin: 0; padding: 0; box-sizing: border-box;}
        body {padding: 20px; font-family: Microsoft YaHei; background: #f5f5f5;}
        .container {max-width: 1200px; margin: 0 auto;}
        .btn-group {margin-bottom: 15px;}
        button {
            padding: 8px 16px;
            margin-right: 10px;
            border: none;
            border-radius: 4px;
            background: #2d8cf0;
            color: #fff;
            cursor: pointer;
            font-size: 14px;
        }
        button:hover {background: #1b76d8;}
        button:disabled {background: #999; cursor: not-allowed;}

        .view-window {
            width: 1000px;
            height: 700px;
            border: 2px solid #ccc;
            overflow: auto;
            background: #fff;
            position: relative;
            margin-bottom: 15px;
        }
        #canvasWrap {position: relative;}
        #imgCanvas {display: block;}
        .select-rect {
            position: absolute;
            border: 2px dashed red;
            background: rgba(255,0,0,0.1);
            pointer-events: none;
        }
        .tip {color: #666; margin-bottom: 10px;}
    </style>
</head>
<body>
    <div class="container">
        <div class="tip">操作:选择图片 → 鼠标拖动框选高度(自动全屏宽度)→ 按【Enter】删除或点按钮 → 支持撤销/重做/还原</div>
        <div class="btn-group">
            <button id="uploadBtn">选择图片</button>
            <button id="delBtn" disabled>删除选区并拼接 (Enter)</button>
            <button id="undoBtn" disabled>撤销</button>
            <button id="redoBtn" disabled>重做</button>
            <button id="resetBtn" disabled>还原图片</button>
            <button id="downloadBtn" disabled>下载最终图片</button>
            <input type="file" id="fileInput" accept="image/*" style="display:none">
        </div>

        <div class="view-window" id="viewWindow">
            <div id="canvasWrap">
                <canvas id="imgCanvas"></canvas>
            </div>
        </div>
    </div>

    <script>
        const fileInput = document.getElementById('fileInput');
        const uploadBtn = document.getElementById('uploadBtn');
        const delBtn = document.getElementById('delBtn');
        const undoBtn = document.getElementById('undoBtn');
        const redoBtn = document.getElementById('redoBtn');
        const resetBtn = document.getElementById('resetBtn');
        const downloadBtn = document.getElementById('downloadBtn');
        const viewWindow = document.getElementById('viewWindow');
        const canvasWrap = document.getElementById('canvasWrap');
        const canvas = document.getElementById('imgCanvas');
        const ctx = canvas.getContext('2d');

        let originImg = null;
        let currentImg = null;
        let history = [];
        let historyIndex = -1;
        let maxHistory = 50;

        let isDrawing = false;
        let startY = 0;
        let rectEl = null;
        let selectRect = { y: 0, h: 0 };

        // 清除旧选区
        function clearSelection() {
            if (rectEl) {
                rectEl.remove();
                rectEl = null;
            }
            selectRect = { y: 0, h: 0 };
        }

        // 保存历史
        function saveHistory() {
            const data = canvas.toDataURL('image/png');
            const img = new Image();
            img.src = data;

            if (historyIndex < history.length - 1) {
                history = history.slice(0, historyIndex + 1);
            }
            history.push(img);
            if (history.length > maxHistory) history.shift();
            historyIndex = history.length - 1;
            updateBtnState();
        }

        // 渲染画布
        function renderCanvas() {
            if (!currentImg) return;
            canvas.width = currentImg.width;
            canvas.height = currentImg.height;
            ctx.clearRect(0, 0, canvas.width, canvas.height);
            ctx.drawImage(currentImg, 0, 0);
        }

        // 更新按钮状态
        function updateBtnState() {
            delBtn.disabled = !currentImg;
            downloadBtn.disabled = !currentImg;
            resetBtn.disabled = !originImg;
            undoBtn.disabled = historyIndex <= 0;
            redoBtn.disabled = historyIndex >= history.length - 1;
        }

        // 选择图片
        uploadBtn.onclick = () => fileInput.click();
        fileInput.onchange = function(e) {
            const file = e.target.files[0];
            if (!file) return;
            const reader = new FileReader();
            reader.onload = function(e) {
                const img = new Image();
                img.onload = function() {
                    originImg = img;
                    currentImg = img;
                    history = [];
                    historyIndex = -1;
                    renderCanvas();
                    saveHistory();
                    updateBtnState();
                };
                img.src = e.target.result;
            };
            reader.readAsDataURL(file);
        };

        // 鼠标开始框选
        viewWindow.addEventListener('mousedown', (e) => {
            if (!currentImg) return;
            clearSelection();

            const rect = canvas.getBoundingClientRect();
            startY = e.clientY - rect.top;
            isDrawing = true;

            rectEl = document.createElement('div');
            rectEl.className = 'select-rect';
            canvasWrap.appendChild(rectEl);
        });

        // 拖动:自动全屏宽度
        viewWindow.addEventListener('mousemove', (e) => {
            if (!isDrawing || !rectEl) return;
            const rect = canvas.getBoundingClientRect();
            const endY = e.clientY - rect.top;

            const imgW = currentImg.width;
            const y = Math.min(startY, endY);
            const h = Math.abs(endY - startY);

            selectRect = { y, h };
            rectEl.style.left = '0px';
            rectEl.style.top = y + 'px';
            rectEl.style.width = imgW + 'px';
            rectEl.style.height = h + 'px';
        });

        viewWindow.addEventListener('mouseup', () => {
            isDrawing = false;
        });

        // 删除 + 拼接
        function deleteAndSplice() {
            if (!currentImg || selectRect.h < 5) {
                alert('请框选有效区域');
                return;
            }
            const { y, h } = selectRect;
            const w = currentImg.width;
            const hTotal = currentImg.height;

            const newCanvas = document.createElement('canvas');
            newCanvas.width = w;
            newCanvas.height = hTotal - h;
            const nCtx = newCanvas.getContext('2d');

            nCtx.drawImage(currentImg, 0, 0, w, y, 0, 0, w, y);
            nCtx.drawImage(currentImg, 0, y + h, w, hTotal - y - h, 0, y, w, hTotal - y - h);

            const newImg = new Image();
            newImg.onload = () => {
                currentImg = newImg;
                renderCanvas();
                saveHistory();
                clearSelection();
            };
            newImg.src = newCanvas.toDataURL('image/png');
        }

        delBtn.onclick = deleteAndSplice;

        // 绑定 Enter 回车键
        document.addEventListener('keydown', (e) => {
            if (e.key === 'Enter') {
                e.preventDefault();
                deleteAndSplice();
            }
        });

        // 撤销
        undoBtn.onclick = () => {
            if (historyIndex <= 0) return;
            historyIndex--;
            currentImg = history[historyIndex];
            renderCanvas();
            clearSelection();
            updateBtnState();
        };

        // 重做
        redoBtn.onclick = () => {
            if (historyIndex >= history.length - 1) return;
            historyIndex++;
            currentImg = history[historyIndex];
            renderCanvas();
            clearSelection();
            updateBtnState();
        };

        // 还原图片
        resetBtn.onclick = () => {
            if (!originImg) return;
            currentImg = originImg;
            renderCanvas();
            clearSelection();
            updateBtnState();
        };

        // 下载
        downloadBtn.onclick = () => {
            const a = document.createElement('a');
            a.download = '裁剪拼接完成.png';
            a.href = canvas.toDataURL('image/png');
            a.click();
        };
    </script>
</body>
</html>

免费评分

参与人数 5吾爱币 +11 热心值 +5 收起 理由
苏紫方璇 + 7 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
yusen7983 + 1 + 1 谢谢@Thanks!
TaPai + 1 + 1 热心回复!
Gfffff + 1 + 1 热心回复!
抱薪风雪雾 + 1 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

提拉米苏子冉 发表于 2026-5-11 08:25
FSCapture可以删除中间的部分,横竖都可以

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
jefel + 1 + 1 谢谢@Thanks!以前一直用FSC,也没发现这个功能,现在学会了!

查看全部评分

znevue 发表于 2026-5-11 11:29
本帖最后由 znevue 于 2026-5-11 11:47 编辑

稍微修改了一下代码,现在横轴纵轴都可以选区删除。
html文件在附件,解压后双击打开就可以直接用。感觉没必要做成exe



flickCoin.zip

4.54 KB, 下载次数: 27, 下载积分: 吾爱币 -1 CB

免费评分

参与人数 1吾爱币 +1 热心值 +1 收起 理由
固相膜 + 1 + 1 谢谢@Thanks!

查看全部评分

抱薪风雪雾 发表于 2026-5-10 22:12
 楼主| joody 发表于 2026-5-10 22:45
不好意思,俺不会,其他坛友可以拿去随意开发,我也想要个exe,新图片直接保存到原始文件夹里面。
snrt 发表于 2026-5-10 23:03
可以几张图片拼个长图,把不要的部分敲掉
17382292086 发表于 2026-5-11 03:50
有EXE版本嘛  按着不错
 楼主| joody 发表于 2026-5-11 04:20
拼长图,喜欢fsv下按alt+t
头像被屏蔽
Gfffff 发表于 2026-5-11 07:46
提示: 该帖被管理员或版主屏蔽
头像被屏蔽
hezhiyong 发表于 2026-5-11 08:11
提示: 该帖被管理员或版主屏蔽
风子是我 发表于 2026-5-11 08:43
html文件我上传了,请见附件,exe的没必要。
水平裁剪测试可用,缺点是没有垂直裁剪的功能。

自动删除拼接.rar

2.56 KB, 下载次数: 8, 下载积分: 吾爱币 -1 CB

您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - 52pojie.cn ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2026-8-10 05:16

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表