(2013-10-17) [latinoware] automatizando o gimp com python

Download (2013-10-17) [LatinoWare] Automatizando o GIMP com Python

If you can't read please download the document

Upload: danilo-j-s-bellini

Post on 16-Apr-2017

327 views

Category:

Design


5 download

TRANSCRIPT

Automatizando o GIMP com Python

PalestranteDanilo de Jesus da Silva Bellinidanilo.bellini [at] gmail.com Twitter: @danilobellini

Proposta deJoo Sebastio de Oliveira Buenogwidion [at] gmail.com Twitter: @gwidion

GIMP http://www.gimp.org/Python http://python.org/

GIMP Python Documentation [by James Henstridge]http://www.gimp.org/docs/python/index.html

Python

MultiparadigmaImperativo/Estrutural

Orientado a objetos

Funcional/Descritivo

Whitespaces tm significadoDelimitao de blocos

Lembra pseudo-cdigo

Multiplataforma

http://python.org/

Especificao e filosofia do Python

PEPs (Python Enhancement Proposal)http://www.python.org/dev/peps

Documentaohttp://docs.python.org

Tutorial feito pelo GuidoExiste traduo para o portugus

PEP20 The Zen of Python

import this

GIMP
The GNU Image Manipulation Program

Raster (Matricial)Image retouching and editing tool

G originalmente era General1995 Incio do desenvolvimento

1996 Primeira verso pblica

S. Kimball e P. Mattis solicitaram a aprovao de R. Stallman para realizar a mudana

1997 GTK The GIMP Tool KitLGPL

Licena [L]GPLv3+The GIMP license has been changed to (L)GPLv3+.http://www.gimp.org/release-notes/gimp-2.7.html

Automao do GIMP com Python
Python-Fu

Python-Fu / Script-FuFu de Kung Fu, pode significar intensidade

Scripts e consoleFilters Python-Fu Console

Arquivos .py executveis no diretrio de plugins

Mesma API do Script-Fu (Scheme)Mtodos de pdb

Nomes com _ ao invs de -

Ignorar parmetros de entrada modo interativo

Mdulo gimpfu

gimp

pdb

register

main

Constantes (nomes 100% em maisculas)PF_INT

PF_BOOL

FG_BUCKET_FILL

ConsoleCalculadora

gimp e pdb j foram importados

Autocomplete (TAB)

Comandos anteriores ()

Built-ins help e dir

Scriptfrom gimpfu import *

O que pdb?

Exemplos
Console

ListaItervel

gimp.image_list

gimp.ImageMtodos width e height

Propriedade layers

gimp.LayerMtodo set_offsetspdb.gimp_layer_set_offsets

Mtodos width e height

Lao forfor elemento in itervel:

: (dois pontos) denota incio de bloco

Melhor detalhado nos prximos 2 slides

Exemplo
(usando GIMP 2.8.2)

File Create Logos Basic II

Usar valores padro

Move Tool (Toolbox)

Mover os layers para qualquer lugar

Layer New Layer

Width = 200 px

Height = 200 px

Layer Fill Type = Foreground color

Como centralizar os layers na imagem?

Padronizao do script

>>> pdb

>>> imgs = gimp.image_list()>>> imgs # Uma lista (valores entre colchetes)[]>>> img = imgs[0]>>> dir(img) # Usar com help tambm[... 'height', ..., 'layers', ..., 'width'] # H mais informao>>> img.layers[, , , , ]>>> len(img.layers)5>>> img.layers[0]

>>> dir(img.layers[0])[... 'height', ..., 'set_offsets', ..., 'width'] # H mais informao>>> img.layers[0].width886>>> for lay in img.layers:... lay.set_offsets(int(.5 * (img.width - lay.width)), int(.5 * (img.height - lay.height)))...>>>

Filters Python-Fu Console

Script

ExemplosCentralizar layer (center_layer.py)

Retngulos (rand_rects.py)

Blur (progressive_blur.py)

InstalaoArquivo .py executvel (chmod +x)

Localizado em ~/.gimp-2.8/plug-ins/ (ou equivalente)

Mensagens no console (debug)

https://bitbucket.org/jsbueno/gimp_scripts

Padronizao do script

from gimpfu import * # register, main, gimp, pdb e constantes

def sua_funcao(img, drw): # Pode ter outros parmetros (e.g., tamanho) # img: objeto gimp.Image # drw: objeto gimp.Layer # Operaes (cuidado ao agrupar operaes de Undo # e ao armazenar a seleo do usurio) gimp.displays_flush() # Atualiza a imagem visualizada

register( proc_name = "sua_funcao", blurb = "blurb", help = "help", author = "Danilo J. S. Bellini", copyright = "GPLv3 - ", date = "2013", label = "/Python-Fu/ApenDanilo", imagetypes = "*", params = [ # (PF_INT, "tamanho", "Uma descrio aqui", 10), ], results = [], function = sua_funcao, #menu = None, # Implcito no "label" #domain = None, on_query=None, on_run=None,)

main()

Obrigado!

Perguntas?

Foz do Iguau PR 2013-10-17 Automatizando o GIMP com PythonDanilo de Jesus da Silva Bellini / Joo Sebastio de Oliveira Bueno