Skip to content

Commit

Permalink
1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
riceshowerX committed Jul 26, 2024
1 parent 13f6aad commit 59aa017
Show file tree
Hide file tree
Showing 16 changed files with 312 additions and 247 deletions.
61 changes: 25 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@

<div align="center" style="display: flex; align-items: center;">
<img src="https://camo.githubusercontent.com/096ea7823f00bd88e3fbfc8d962b41bfebda269c12050c528760d07307ea5e4e/68747470733a2f2f7269636573686f776572582e6769746875622e696f2f706963782d696d616765732d686f7374696e672fe7a4bee4baa4e5a4b4e5838f2e337965616c35396437622e77656270" alt="Logo" width="70" height="70" style="margin-right: 10px;">
<img src="https://camo.githubusercontent.com/096ea7823f00bd88e3fbfc8d962b41bfebda269c12050c528760d07307ea5e4e/68747470733a2f2f726963657273686f776572582e6769746875622e696f2f706963782d696d616765732d686f7374696e672fe7a4bee4baa4e5a4b4e5838f2e337965616c35396437622e77656270" alt="Logo" width="70" height="70" style="margin-right: 10px;">
<h1>SnapForge</h1>
</div>

<p align="center">
🎨 **SnapForge 是一款全面的图像处理工具,提供批量重命名、格式转换和压缩功能,为您的图像管理需求提供高效解决方案!**
🎨 **SnapForge 是一款用 PyQt6 打造的跨平台图像处理工具,提供批量重命名、格式转换和压缩功能,为您的图像管理需求提供高效解决方案!**
</p>

<p align="center">
Expand All @@ -20,52 +19,42 @@
- 🖼️ **批量重命名**: 高效处理多个图像文件,支持自定义前缀和编号。
- 🔄 **批量格式转换**: 轻松将图像转换为各种格式,如JPEG、PNG等,方便使用。
- 🗜️ **批量压缩**: 在保持图像质量的同时减少文件大小,优化存储和加载速度。
- 💻 **跨平台**: 支持 Windows, macOS, 和 Linux 系统.
- 🌐 **中文用户界面**: 提供直观的中文图形用户界面,使操作更加简便。

## 🚀 快速开始

### 克隆代码库
### 1. 克隆代码库

```bash
git clone https://github.com/riceshowerX/SnapForge.git
```

### 安装依赖

```bash
Use code with caution.
Markdown
2. 安装依赖
cd SnapForge
pip install -r requirements.txt
```

### 启动 SnapForge

运行应用程序:

```bash
python main.py
```

## 🎨 特性实现状态

| 特性 | 实现状态 |
|------------------------|----------|
| 批量重命名 ||
| 批量格式转换 ||
| 批量压缩 ||
| 直观的用户界面 ||
| 详细的日志记录 ||
| 多语言支持 ||
| 高级图像处理功能 ||

## 🤝 贡献

Use code with caution.
Bash
3. 启动 SnapForge
python gui.py
Use code with caution.
Bash
🎨 截图
(这里可以添加几张应用程序截图)
🤝 贡献
我们热烈欢迎您的贡献!

如果您有任何想法、建议或发现任何问题,请随时提交 pull request 或开启 issue。本项目由个人在业余时间开发和维护,因此开发和修复进度可能较慢,且不定期进行更新。我们感谢您的理解和支持,并欢迎通过提交 issue 或 pull request 来帮助改进项目。
⚖️ 许可证
SnapForge 使用 Apache License 2.0 许可。详细信息请参阅 LICENSE 文件。
**修改说明:**

## ⚖️ 许可证
* **项目描述:** 补充说明使用 PyQt6 开发,以及跨平台特性。
* **快速开始:** 更新了启动命令。
* **特性实现状态:** 删除了与项目无关的内容。
* **免责声明:** 删除了与项目无关的内容。
* **截图:** 建议添加几张应用程序截图,可以更直观地展示项目。

SnapForge 使用 Apache License 2.0 许可。详细信息请参阅 [LICENSE](https://github.com/riceshowerX/SnapForge/blob/main/LICENSE) 文件。
希望这些调整对你的项目有所帮助!

## ⚠️ 免责声明

Expand Down
Binary file removed __pycache__/batch_compress.cpython-312.pyc
Binary file not shown.
Binary file removed __pycache__/batch_convert.cpython-312.pyc
Binary file not shown.
Binary file removed __pycache__/batch_rename.cpython-312.pyc
Binary file not shown.
14 changes: 0 additions & 14 deletions batch_compress.py

This file was deleted.

15 changes: 0 additions & 15 deletions batch_convert.py

This file was deleted.

13 changes: 0 additions & 13 deletions batch_rename.py

This file was deleted.

172 changes: 172 additions & 0 deletions gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# gui.py
from PyQt6.QtWidgets import QApplication, QMainWindow, QFileDialog, QVBoxLayout, QPushButton, QLineEdit, QLabel, QWidget, QMessageBox, QProgressBar
from PyQt6.QtCore import Qt
from utils import image_processor
import sys

class ImageProcessingApp(QMainWindow):
def __init__(self):
super().__init__()

self.setWindowTitle("图片处理工具")
self.resize(400, 350)

self.source_directory = None
self.target_directory = None

self.init_ui()

def init_ui(self):
layout = QVBoxLayout()

# 选择文件夹
self.source_label = QLabel("选择原始图片文件夹:")
self.source_button = QPushButton("选择文件夹")
self.source_button.clicked.connect(self.select_source_directory)

self.target_label = QLabel("选择保存图片文件夹:")
self.target_button = QPushButton("选择文件夹")
self.target_button.clicked.connect(self.select_target_directory)

layout.addWidget(self.source_label)
layout.addWidget(self.source_button)
layout.addWidget(self.target_label)
layout.addWidget(self.target_button)

# 批量重命名
self.prefix_label = QLabel("前缀:")
self.prefix_entry = QLineEdit()
self.start_number_label = QLabel("起始编号:")
self.start_number_entry = QLineEdit("1")
self.rename_button = QPushButton("执行重命名")
self.rename_button.clicked.connect(self.rename_files)

layout.addWidget(self.prefix_label)
layout.addWidget(self.prefix_entry)
layout.addWidget(self.start_number_label)
layout.addWidget(self.start_number_entry)
layout.addWidget(self.rename_button)

# 批量转换
self.format_label = QLabel("目标格式 (如 jpeg, png):")
self.format_entry = QLineEdit()
self.convert_button = QPushButton("执行转换")
self.convert_button.clicked.connect(self.convert_files)

layout.addWidget(self.format_label)
layout.addWidget(self.format_entry)
layout.addWidget(self.convert_button)

# 批量压缩
self.quality_label = QLabel("压缩质量 (1-100):")
self.quality_entry = QLineEdit("80")
self.compress_button = QPushButton("执行压缩")
self.compress_button.clicked.connect(self.compress_files)

layout.addWidget(self.quality_label)
layout.addWidget(self.quality_entry)
layout.addWidget(self.compress_button)

# 进度条
self.progress_bar = QProgressBar()
self.progress_bar.setValue(0)
self.progress_bar.setAlignment(Qt.AlignmentFlag.AlignCenter)
layout.addWidget(self.progress_bar)

container = QWidget()
container.setLayout(layout)
self.setCentralWidget(container)

def select_source_directory(self):
self.source_directory = QFileDialog.getExistingDirectory(self, "选择原始图片文件夹")

def select_target_directory(self):
self.target_directory = QFileDialog.getExistingDirectory(self, "选择保存图片文件夹")

def rename_files(self):
if not self.source_directory or not self.target_directory:
QMessageBox.warning(self, "警告", "请先选择原始和保存图片文件夹!")
return

prefix = self.prefix_entry.text()
try:
start_number = int(self.start_number_entry.text())
except ValueError:
QMessageBox.warning(self, "警告", "起始编号必须是一个整数!")
return

try:
renamed_count = image_processor.batch_rename_files(
self.source_directory,
self.target_directory,
prefix,
start_number,
self.update_progress_bar
)
QMessageBox.information(self, "结果", f"重命名完成!共重命名了 {renamed_count} 个文件。")
except Exception as e:
# 处理其他潜在的异常
QMessageBox.warning(self, "错误", f"发生错误: {e}")


def convert_files(self):
if not self.source_directory or not self.target_directory:
QMessageBox.warning(self, "警告", "请先选择原始和保存图片文件夹!")
return

target_format = self.format_entry.text().lower()
if not target_format:
QMessageBox.warning(self, "警告", "目标格式不能为空!")
return

try:
converted_count = image_processor.batch_convert_images(
self.source_directory,
self.target_directory,
target_format,
self.update_progress_bar
)
QMessageBox.information(self, "结果", f"格式转换完成!共转换了 {converted_count} 个文件。")
except Exception as e:
# 处理其他潜在的异常
QMessageBox.warning(self, "错误", f"发生错误: {e}")

def compress_files(self):
if not self.source_directory or not self.target_directory:
QMessageBox.warning(self, "警告", "请先选择原始和保存图片文件夹!")
return

try:
quality = int(self.quality_entry.text())
if quality < 1 or quality > 100:
raise ValueError
except ValueError:
QMessageBox.warning(self, "警告", "压缩质量必须是1到100之间的整数!")
return

try:
compressed_count = image_processor.batch_compress_images(
self.source_directory,
self.target_directory,
quality,
self.update_progress_bar
)
QMessageBox.information(self, "结果", f"压缩完成!共压缩了 {compressed_count} 个文件。")
except Exception as e:
# 处理其他潜在的异常
QMessageBox.warning(self, "错误", f"发生错误: {e}")

def update_progress_bar(self, current, total):
"""更新进度条。
Args:
current (int): 当前进度。
total (int): 总进度。
"""
self.progress_bar.setValue(int(current / total * 100))

if __name__ == "__main__":
app = QApplication(sys.argv)
window = ImageProcessingApp()
window.show()
sys.exit(app.exec())
Loading

0 comments on commit 59aa017

Please sign in to comment.