Main Page | Report this Page

 




 

 

Computers Forum Index  »  Computer - Graphics - Applications (Gimp)  »  new script fu ! - Add a Picture Frame + Matte to an image
Page 1 of 1    

new script fu ! - Add a Picture Frame + Matte to an image

Author Message
howard smith
Posted: Thu Mar 17, 2005 4:02 am
Guest
Here's a new scriptFu to generate a picture frame+matte
around an image. If someone could submit this to be
reviewed/included in the next gimp release, that'd be
great.

newframe.scm ScriptFu
---------------------------------------------------------
; The GIMP -- an image manipulation program
; Copyright (C) 1995 Spencer Kimball and Peter Mattis
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;
; Copyright (C) 2005 Howard Smith hcharles@mindspring.com
;
; Version 0.1
;; code extended from addborder.scm , Andy Thomas



(define (gen_top_array xsize ysize owidth oheight width height)
(let* ((n_array (cons-array 10 'double)))
(aset n_array 0 0 )
(aset n_array 1 0 )
(aset n_array 2 xsize)
(aset n_array 3 ysize)
(aset n_array 4 (- width xsize ))
(aset n_array 5 ysize)
(aset n_array 6 width)
(aset n_array 7 0 )
(aset n_array 8 0 )
(aset n_array 9 0 )
n_array)
)

(define (gen_left_array xsize ysize owidth oheight width height)
(let* ((n_array (cons-array 10 'double)))
(aset n_array 0 0 )
(aset n_array 1 0 )
(aset n_array 2 xsize)
(aset n_array 3 ysize)
(aset n_array 4 xsize)
(aset n_array 5 (- height ysize ))
(aset n_array 6 0 )
(aset n_array 7 height )
(aset n_array 8 0 )
(aset n_array 9 0 )
n_array)
)

(define (gen_right_array xsize ysize owidth oheight width height)
(let* ((n_array (cons-array 10 'double)))
(aset n_array 0 width )
(aset n_array 1 0 )
(aset n_array 2 (- width xsize ))
(aset n_array 3 ysize)
(aset n_array 4 (- width xsize ))
(aset n_array 5 (- height ysize ))
(aset n_array 6 width)
(aset n_array 7 height)
(aset n_array 8 width )
(aset n_array 9 0 )
n_array)
)

(define (gen_bottom_array xsize ysize owidth oheight width height)
(let* ((n_array (cons-array 10 'double)))
(aset n_array 0 0 )
(aset n_array 1 height)
(aset n_array 2 xsize)
(aset n_array 3 (- height ysize))
(aset n_array 4 (- width xsize))
(aset n_array 5 (- height ysize))
(aset n_array 6 width)
(aset n_array 7 height)
(aset n_array 8 0 )
(aset n_array 9 height)
n_array)
)


(define (gen_frame_array xsize ysize owidth oheight width height)
(let* ((n_array (cons-array 10 'double)))
(aset n_array 0 xsize )
(aset n_array 1 ysize )
(aset n_array 2 xsize )
(aset n_array 3 (+ ysize oheight))
(aset n_array 4 (+ xsize owidth))
(aset n_array 5 (+ ysize oheight))
(aset n_array 6 (+ xsize owidth))
(aset n_array 7 ysize)
(aset n_array 8 xsize )
(aset n_array 9 ysize)
n_array)
)


(define (script-fu-addframe aimg adraw fwid fhei fgrad mwid mhei mcolor )
(let* ((img (car (gimp-drawable-get-image adraw)))
(owidth (car (gimp-image-width img)))
(oheight (car (gimp-image-height img)))

(mattewid (+ owidth mwid ))
(mattehei (+ oheight mhei ))
(twid (+ fwid mwid ))
(thei (+ fhei mhei ))
(width (+ owidth (* 2 twid ) ) )
(height (+ oheight (* 2 thei ) ) )

(layerM (car (gimp-layer-new img
width height
(car (gimp-drawable-type-with-alpha adraw))
"Matte-Layer" 100 NORMAL-MODE)))

(layerF (car (gimp-layer-new img
width height
(car (gimp-drawable-type-with-alpha adraw))
"Frame-Layer" 100 NORMAL-MODE))))

;Add this for debugging (verbose 4)

(gimp-context-push)

(gimp-image-undo-group-start img)

(gimp-image-resize img
width
height
twid
thei )

; draw matte layer

(gimp-image-add-layer img layerM 0)
(gimp-drawable-fill layerM TRANSPARENT-FILL)
(gimp-free-select img
10
(gen_frame_array twid thei owidth oheight width height)
CHANNEL-OP-REPLACE
0
0
0.0)
(gimp-selection-invert img)
(gimp-context-set-background mcolor)
(gimp-edit-fill layerM BACKGROUND-FILL )
(gimp-selection-none img)

; draw frame layer

(gimp-image-add-layer img layerF 0)
(gimp-drawable-fill layerF TRANSPARENT-FILL)


; top
(gimp-free-select img
10
(gen_top_array fwid fhei mattewid mattehei width height)
CHANNEL-OP-REPLACE
0
0
0.0)
(gimp-context-set-gradient fgrad)
(gimp-edit-blend layerF CUSTOM-MODE NORMAL-MODE
GRADIENT-LINEAR 100 0 REPEAT-NONE FALSE
FALSE 0 0 TRUE
0 0 0 fhei )
; left
(gimp-free-select img
10
(gen_left_array fwid fhei mattewid mattehei width height)
CHANNEL-OP-REPLACE
0
0
0.0)
(gimp-context-set-gradient fgrad)
(gimp-edit-blend layerF CUSTOM-MODE NORMAL-MODE
GRADIENT-LINEAR 100 0 REPEAT-NONE FALSE
FALSE 0 0 TRUE
0 0 fwid 0 )


; right
(gimp-free-select img
10
(gen_right_array fwid fhei mattewid mattehei width height)
CHANNEL-OP-REPLACE
0
0
0.0)
(gimp-context-set-gradient fgrad)
(gimp-edit-blend layerF CUSTOM-MODE NORMAL-MODE
GRADIENT-LINEAR 100 0 REPEAT-NONE FALSE
FALSE 0 0 TRUE
width 0 (- width fwid) 0 )

; bottom
(gimp-free-select img
10
(gen_bottom_array fwid fhei mattewid mattehei width height)
CHANNEL-OP-REPLACE
0
0
0.0)

(gimp-context-set-gradient fgrad)
(gimp-edit-blend layerF CUSTOM-MODE NORMAL-MODE
GRADIENT-LINEAR 100 0 REPEAT-NONE FALSE
FALSE 0 0 TRUE
0 height 0 (- height fhei ) )
(gimp-selection-none img)
(gimp-image-undo-group-end img)
(gimp-displays-flush)

(gimp-context-pop)))

(script-fu-register "script-fu-addframe"
_"Add _Frame..."
"Add a picture frame around an image with optional matte"

"Howard Smith <hcharles@mindspring.com>"
"Howard Smith"
"Mar 01 2005"
"*"
SF-IMAGE "Input image" 0
SF-DRAWABLE "Input drawable" 0
SF-ADJUSTMENT _"Frame width" '(15 1 250 1 10 0 1)
SF-ADJUSTMENT _"Frame height" '(15 1 250 1 10 0 1)
SF-GRADIENT _"Frame Gradient" "Golden"
SF-ADJUSTMENT _"Matte width" '(40 1 250 1 10 0 1)
SF-ADJUSTMENT _"Matte height" '(40 1 250 1 10 0 1)
SF-COLOR _"Matte color" '(245 245 245))



(script-fu-menu-register "script-fu-addframe"
_"<Image>/Script-Fu/Decor")
 
Branko Collin
Posted: Thu Mar 17, 2005 10:02 pm
Guest
howard smith <hcharles@mindspring.com>, you wrote on Wed, 16 Mar 2005
22:19:11 -0500:

Quote:
Here's a new scriptFu to generate a picture frame+matte
around an image. If someone could submit this to be
reviewed/included in the next gimp release, that'd be
great.

[snipped script]

There are perhaps better places to post this. For instance,
<http://gug.sunsite.dk/scripts.php> and <http://registry.gimp.org>.

If you want a new feature included in the GIMP, you may try and post a
feature request at <http://bugzilla.gnome.org/>.

Keep in mind that the core GIMP developers have a long-term goal*: to
reduce the number of plug-ins shipped with the GIMP, to be replaced
with a plug-in manager. New plug-ins may not be too welcome, therefor.
(On the other hand, new plug-ins have found their way into the GIMP,
the guideline functions for example, so you should always try).

(* This from when I was still subscribed to the developers list.
Things may have changed since.)

--
Deze geheele aarde door ijzeren banden omspannen, met de
stoomvaartlijnen die als draden over de zeeën zijn getrokken,
Dezen wereldkloot in zijn tuimeling door het heelal breng ik U.
"Grashalmen", Walt Whitman, http://www.gutenberg.org/etext/14281
 
 
Page 1 of 1    
All times are GMT
The time now is Sat Jul 31, 2010 9:32 pm