Created
November 17, 2012 23:16
-
-
Save natchiketa/4101280 to your computer and use it in GitHub Desktop.
GIMP Python-Fu function to generate CSS gradient based on current selection bounds
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def pushgrad(options={}, use_gradient_name=True, image_index=0): | |
| img = gimp.image_list()[image_index] | |
| sel = pdb.gimp_selection_bounds(img) | |
| left, top = sel[1], sel[2] | |
| width = sel[3] - left | |
| height = sel[4] - top | |
| # The following variable, prefix, is what I prefix all of my gradient names in GIMP. Change this to | |
| # fit your situation. | |
| prefix = 'natcss_' | |
| if use_gradient_name: | |
| active_gradient_name = pdb.gimp_context_get_gradient(img).replace(prefix, '') | |
| grad_colors = {'linear':active_gradient_name,'radial':active_gradient_name} | |
| else: | |
| grad_colors = {'linear':'black 0%, black 100%','radial':'transparent 98%, black 100%'} | |
| # DEFAULTS | |
| grad_type = options.get('type', 'linear') | |
| grad_angle = options.get('deg', '90deg') | |
| grad_shape = options.get('shape', 'ellipse') | |
| grad_size = options.get('size', 'closest-side') | |
| grad_position = options.get('pos', 'center center') | |
| grad_linear = 'ling(%s, (%s)' % (grad_angle, grad_colors[grad_type]) | |
| grad_radial = 'radg(%s, %s, %s, (%s)' % (grad_shape, grad_size, grad_position, grad_colors[grad_type]) | |
| grad_types = {'linear': grad_linear, 'radial': grad_radial} | |
| print '\n$gv: pushgrad(%s, (%dpx %dpx), (%dpx %dpx), $s));\n' % (grad_types[grad_type], left, top, width, height) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment