English 中文(简体)
Python- fu GIMP 脚本不粘贴图像
原标题:Python-fu GIMP script do not paste image

我试图写一个脚本, 将一个层切成小和平。 它运行正确, 但没有什么被粘贴到一个新的层 。

def explode_layer( i, l, dx, dy ):
    T=[]
    for ix,ox in enumerate(range(l.offsets[0], l.offsets[0]+l.width, dx )):
        for iy,oy in enumerate(range(l.offsets[1], l.offsets[1]+l.height, dy)):
            pdb.gimp_rect_select(i, ox, oy, dx, dy, 2, False, 0)
            if not pdb.gimp_edit_copy(l):
                continue
            layer = pdb.gimp_layer_new(i, dx, dy, 1, 
                                       l.name+" %d,%d"%(ix,iy), 100, 0)
            i.add_layer(layer)
            floating_sel = pdb.gimp_edit_paste(layer, True)
            pdb.gimp_layer_set_offsets(floating_sel, *layer.offsets)
            pdb.gimp_floating_sel_anchor(floating_sel)
            T.append(layer)
    return T

I use gimp 2.6.8 on Ubuntu 10.04. How can I fix it? Is there a better approach?

最佳回答

I am taking a look at your script now - it is a good approach -and I found out what is wrong: when you call gimp_edit_paste, the selection you created (with gimp_rect_select) is still active, and the contents of your floated layer are clipped by it. (Actually I think they are clipepd just at the "selection_anchor" call, but that is irrelevant).

因此,在 < code> floating_sel = pdb.gimp_edit_paste( layer, True) 修正您的功能之前,添加 pdb. dedit_edit_paste( True) 线 :

def explode_layer( i, l, dx, dy ):
    T=[]
    for ix,ox in enumerate(range(l.offsets[0], l.offsets[0]+l.width, dx )):
        for iy,oy in enumerate(range(l.offsets[1], l.offsets[1]+l.height, dy)):
            pdb.gimp_rect_select(i, ox, oy, dx, dy, 2, False, 0)
            if not pdb.gimp_edit_copy(l):
                continue
            layer = pdb.gimp_layer_new(i, dx, dy, 1, 
                                       l.name+" %d,%d"%(ix,iy), 100, 0)
            i.add_layer(layer)
            pdb.gimp_selection_none(i)
            floating_sel = pdb.gimp_edit_paste(layer, True)
            pdb.gimp_layer_set_offsets(floating_sel, *layer.offsets)
            pdb.gimp_floating_sel_anchor(floating_sel)
            T.append(layer)
    return T

简单的方法是,不是明确地创建一个新的层(btw, 虽然在图像对象上有一个没有证明的“ 新层” 方法, 以创建和添加新层, 并且对大多数参数有正常默认值 - 所以, i. new_layer( & lt; name>, & lt; width>, & lt; h88>) 将足够) - 但是您可以简单地复制、 粘贴, 并且它们调用 < code> new_ lay = pdb. gim_ floating_ sel_ to_ layer( & lt; floating_ sel>)

问题回答

暂无回答




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签