使用 GIMP 插件批量剪裁和处理负片

1,667次阅读
没有评论

本篇技术博客文章由 ChatGPTGPT-4)编写。本文将介绍如何使用 GIMP 插件来批量剪裁、处理负片,插件支持 .jpg 和 .jpeg 文件格式,用户可以选择是否对图像进行去色处理。

如果您曾经需要手动剪裁和处理多张负片,您就知道这需要花费大量的时间和精力。幸运的是,有了 Batch Crop and Process Negatives GIMP 插件,您可以自动化该过程,节省大量时间和精力。

使用 GIMP 插件批量剪裁和处理负片

安装

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from gimpfu import *
import os

def batch_crop_and_process_negatives(input_directory, output_directory, convert_to_bw, x, y, width, height):
# 获取输入文件夹中的所有JPG文件
input_files = [f for f in os.listdir(input_directory) if f.lower().endswith((".jpg", ".jpeg"))]

for input_file in input_files:
# 打开输入文件
image_path = os.path.join(input_directory, input_file)
image = pdb.gimp_file_load(image_path, image_path)
drawable = pdb.gimp_image_get_active_layer(image)

# 剪裁图像
pdb.gimp_image_crop(image, width, height, x, y)

# 是否去色
if convert_to_bw:
pdb.gimp_desaturate_full(drawable, DESATURATE_LUMINOSITY)

# 反相
pdb.gimp_invert(drawable)

# 自动调整色阶
pdb.gimp_levels_stretch(drawable)

# 保存处理后的文件
output_path = os.path.join(output_directory, input_file)
pdb.gimp_file_save(image, drawable, output_path, output_path)

# 关闭图片
pdb.gimp_image_delete(image)

register(
"python_fu_batch_crop_and_process_negatives",
"Batch Crop and Process Negatives",
"Crops, inverts colors, and adjusts levels of all JPEG images in the input directory, then saves them in the output directory.",
"OpenAI",
"OpenAI",
"2023",
"Batch Crop and Process Negatives...",
"",
[
(PF_DIRNAME, "input_directory", "Input directory", ""),
(PF_DIRNAME, "output_directory", "Output directory", ""),
(PF_BOOL, "convert_to_bw", "Convert to black and white", False),
(PF_INT, "x", "Crop X offset", 0),
(PF_INT, "y", "Crop Y offset", 0),
(PF_INT, "width", "Crop width", 100),
(PF_INT, "height", "Crop height", 100),
],
[],
batch_crop_and_process_negatives,
menu="<Image>/Filters/Custom"
)

main()
  1. 安装 GIMP 图像处理软件
  2. 将上述代码复制到一个名为 batch_crop_and_process_negatives.py 的文件中。
  3. 将该文件放置在 GIMP 的插件目录下。通常,该目录位于以下位置:
    • Windows: C:Users<用户名>AppDataRoamingGIMP<版本号>plug-ins
    • macOS: ~/Library/Application Support/GIMP/<版本号>/plug-ins
    • Linux: ~/.config/GIMP/<版本号>/plug-ins
  4. 确保文件具有可执行权限(在 macOS 和 Linux 系统上)。
  5. 重新启动 GIMP。

使用

  1. 启动 GIMP。
  2. 点击菜单栏中的「Filters」(滤镜)>「Custom」(自定义)>「Batch Crop and Process Negatives…」。
  3. 在弹出的对话框中,设置以下参数:
    • Input directory(输入目录):包含要处理的 .jpg 和 .jpeg 图像文件的文件夹。
    • Output directory(输出目录):处理后的图像将保存到该文件夹。
    • Convert to black and white(转换为黑白):勾选此选项以将图像转换为黑白模式。
    • Crop X offset(剪裁 X 偏移):剪裁区域距离图像左侧的距离。
    • Crop Y offset(剪裁 Y 偏移):剪裁区域距离图像顶部的距离。
    • Crop width(剪裁宽度):剪裁区域的宽度。
    • Crop height(剪裁高度):剪裁区域的高度。
  4. 点击「OK」开始处理。插件将遍历输入目录中的所有图像文件,按照设置的参数进行剪裁和处理,然后将结果保存到输出目录。

获取剪裁参数

要确定剪裁参数(Crop X offset、Crop Y offset、Crop width 和 Crop height),您可以先在 GIMP 中手动剪裁一张图片,然后获取所需的参数值。

  1. 在 GIMP 中打开一张需要剪裁的图片。
  2. 选择「矩形选择工具」(快捷键 R)。
  3. 在图片上绘制一个矩形区域,表示您想要剪裁的部分。
  4. 在「工具选项」窗口中,您可以看到「位置」和「大小」参数。其中,位置对应于 Crop X offset 和 Crop Y offset,大小对应于 Crop width 和 Crop height。
  5. 将这些参数值输入插件对话框中的相应字段。

注意事项

  • 为确保一致的剪裁,请确保所有图像均采自相同位置。
  • 该插件仅支持 .jpg 和 .jpeg 文件格式。
  • 该插件将处理后的图像保存到输出目录中,不会更改原始图像。
  • 处理大量图像时,该插件可能需要一些时间才能完成,请耐心等待。
  • 在插件运行时,请避免在 GIMP 中执行其他操作,以免干扰插件运行。

通过使用此插件,您可以轻松地批量剪裁和处理多个图像,无需手动对每个文件进行相同的操作。希望这对您的工作有所帮助!

 

Read More 

正文完
可以使用微信扫码关注公众号(ID:xzluomor)
post-qrcode
 0
评论(没有评论)

文心AIGC

2023 年 5 月
1234567
891011121314
15161718192021
22232425262728
293031  
文心AIGC
文心AIGC
人工智能ChatGPT,AIGC指利用人工智能技术来生成内容,其中包括文字、语音、代码、图像、视频、机器人动作等等。被认为是继PGC、UGC之后的新型内容创作方式。AIGC作为元宇宙的新方向,近几年迭代速度呈现指数级爆发,谷歌、Meta、百度等平台型巨头持续布局
文章搜索
热门文章
潞晨尤洋:日常办公没必要上私有模型,这三类企业才需要 | MEET2026

潞晨尤洋:日常办公没必要上私有模型,这三类企业才需要 | MEET2026

潞晨尤洋:日常办公没必要上私有模型,这三类企业才需要 | MEET2026 Jay 2025-12-22 09...
“昆山杯”第二十七届清华大学创业大赛决赛举行

“昆山杯”第二十七届清华大学创业大赛决赛举行

“昆山杯”第二十七届清华大学创业大赛决赛举行 一水 2025-12-22 17:04:24 来源:量子位 本届...
MiniMax海螺视频团队首次开源:Tokenizer也具备明确的Scaling Law

MiniMax海螺视频团队首次开源:Tokenizer也具备明确的Scaling Law

MiniMax海螺视频团队首次开源:Tokenizer也具备明确的Scaling Law 一水 2025-12...
天下苦SaaS已久,企业级AI得靠「结果」说话

天下苦SaaS已久,企业级AI得靠「结果」说话

天下苦SaaS已久,企业级AI得靠「结果」说话 Jay 2025-12-22 13:46:04 来源:量子位 ...
最新评论
ufabet ufabet มีเกมให้เลือกเล่นมากมาย: เกมเดิมพันหลากหลาย ครบทุกค่ายดัง
tornado crypto mixer tornado crypto mixer Discover the power of privacy with TornadoCash! Learn how this decentralized mixer ensures your transactions remain confidential.
ดูบอลสด ดูบอลสด Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
ดูบอลสด ดูบอลสด Pretty! This has been a really wonderful post. Many thanks for providing these details.
ดูบอลสด ดูบอลสด Pretty! This has been a really wonderful post. Many thanks for providing these details.
ดูบอลสด ดูบอลสด Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.
Obrazy Sztuka Nowoczesna Obrazy Sztuka Nowoczesna Thank you for this wonderful contribution to the topic. Your ability to explain complex ideas simply is admirable.
ufabet ufabet Hi there to all, for the reason that I am genuinely keen of reading this website’s post to be updated on a regular basis. It carries pleasant stuff.
ufabet ufabet You’re so awesome! I don’t believe I have read a single thing like that before. So great to find someone with some original thoughts on this topic. Really.. thank you for starting this up. This website is something that is needed on the internet, someone with a little originality!
ufabet ufabet Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.
热评文章
摩尔线程的野心,不藏了

摩尔线程的野心,不藏了

摩尔线程的野心,不藏了 量子位的朋友们 2025-12-22 10:11:58 来源:量子位 上市后的仅15天...
摩尔线程的野心,不藏了

摩尔线程的野心,不藏了

摩尔线程的野心,不藏了 量子位的朋友们 2025-12-22 10:11:58 来源:量子位 上市后的仅15天...
AI体育教练来了!中国团队打造SportsGPT,完成从数值评估到专业指导的智能转身

AI体育教练来了!中国团队打造SportsGPT,完成从数值评估到专业指导的智能转身

AI体育教练来了!中国团队打造SportsGPT,完成从数值评估到专业指导的智能转身 量子位的朋友们 2025...
AI体育教练来了!中国团队打造SportsGPT,完成从数值评估到专业指导的智能转身

AI体育教练来了!中国团队打造SportsGPT,完成从数值评估到专业指导的智能转身

AI体育教练来了!中国团队打造SportsGPT,完成从数值评估到专业指导的智能转身 量子位的朋友们 2025...
真正面向大模型的AI Infra,必须同时懂模型、系统、产业|商汤大装置宣善明@MEET2026

真正面向大模型的AI Infra,必须同时懂模型、系统、产业|商汤大装置宣善明@MEET2026

真正面向大模型的AI Infra,必须同时懂模型、系统、产业|商汤大装置宣善明@MEET2026 量子位的朋友...