首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >python-fu选择复制粘贴

python-fu选择复制粘贴
EN

Stack Overflow用户
提问于 2013-12-13 01:17:09
回答 1查看 3.5K关注 0票数 3

我是python-fu的新手(第二天),所以我的问题可能看起来很天真:我想从"r400r.png“中选择一个矩形部分,将其旋转90度,然后将选择保存在"r400ra.png”中。

到目前为止,我在这些代码行上尝试了一些东西:

代码语言:javascript
复制
for fv in range(400,401):
  fn='r%sr.png' % fv
  img=pdb.gimp_file_load('/path/'+fn,fn)
  drw=pdb.gimp_image_get_active_layer(img)
  img1=pdb.gimp_image_new(1024,1568,0)
  lyr=pdb.gimp_layer_new(img1,1024,1568,0,'ly1',0,0)

  pdb.gimp_rect_select(img,10,200,1422,1024,2,0,0)
  drw=pdb.gimp_rotate(drw,0,1.570796327)
  pdb.script_fu_selection_to_image(img1,drw)
  f0=fn[:5]+'a'+fn[5:]
  pdb.gimp_file_save(drw,'/path/'+f0,f0)

"lyr“层在那里是因为我的理解是它是必须的,尽管我不清楚为什么。" for“循环最终应该批量处理一堆文件;为了进行测试,它仅限于一个文件。当我尝试执行"script_fu_selection_to_image“时,我得到一个错误。

你能给我指个方向吗?

谢谢,SxN

EN

回答 1

Stack Overflow用户

发布于 2013-12-27 00:24:05

执行此操作的PDB调用按以下顺序更好:

代码语言:javascript
复制
# import your image:
img=pdb.gimp_file_load('/path/'+fn,fn)

#make the selection
pdb.gimp_rect_select(img,10,200,1422,1024,2,0,0)


# copy
pdb.gimp_edit_copy(img.layers[0])
# (no need to "get_active_layer" - if
# your image is a flat PNG or JPG, it only has one layer,
# which is accessible as img.layers[0]) 

# create a new image from the copied area:
new_img = pdb.gimp_paste_as_new()

#rotate the newly created image:
pdb.gimp_image_rotate(new_img, ...)

#export the resulting image:
pdb.gimp_file_save(new_img, ...)

#delete the loaded image and the created image:
# (as the objects being destroyed on the Python side
# do not erase then from the GIMP app, where they
# stay consuming memory)
pdb.gimp_image_delete(new_img)
pdb.gimp_image_delete(img)
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20549908

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档