首页 > 其他 > 详细

GIMP 一键均匀添加多条参考线

时间:2020-07-19 12:00:53      阅读:84      评论:0      收藏:0      [点我收藏+]
#!/usr/bin/env python2
# -*- coding: utf-8 -*-

from gimpfu import *

# orientation: ORIENTATION_HORIZONTAL(0), ORIENTATION_VERTICAL(1)
# diff: 参考线之间的间隔
def add_multi_guides(orientation, diff):
    imgs = gimp.image_list()
    if len(imgs) == 0:
        return
    img = imgs[0]

    w, h = img.width, img.height
    endposition = None
    add_guide = None

    if orientation == ORIENTATION_HORIZONTAL:
        assert diff < h, ‘diff too big‘
        endposition = h
        add_guide = pdb.gimp_image_add_hguide
    elif orientation == ORIENTATION_VERTICAL:
        assert diff < w, ‘diff too big‘
        endposition = w
        add_guide = pdb.gimp_image_add_vguide
    else:
        raise ValueError((‘orientation not valid: {0}‘).format(orientation))

    # 清空原来的参考线
    guide = pdb.gimp_image_find_next_guide(img, 0)
    while guide != 0:
        if orientation == pdb.gimp_image_get_guide_orientation(img, guide):
            pdb.gimp_image_delete_guide(img, guide)
            guide = 0
        guide = pdb.gimp_image_find_next_guide(img, guide)

    position = diff
    while position < endposition:
        add_guide(img, position)
        position = position + diff


register(
    "add_multi_guides",
    # table snippet means a small piece of HTML code here
    "Add fucking guides",
    "long description",
    "hangj",
    "hangj",
    "2020",
    "Add Multi Guides...",
    "",
    [
        (PF_OPTION, "orientation", "orientation", 0, ("HORIZONTAL", "VERTICAL")),
        (PF_INT, "diff", "pixcels between guides", 1000)
    ],
    [],
    add_multi_guides,
    menu="<Image>/Image/Guides"
    )

main()

把脚本保存,放到 plug-ins 目录下,然后chmod +x filename,重启 GIMP

GIMP 一键均匀添加多条参考线

原文:https://www.cnblogs.com/hangj/p/13338502.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!