~ubuntu-branches/ubuntu/hoary/gimp/hoary

« back to all changes in this revision

Viewing changes to plug-ins/script-fu/scripts/round-corners.scm

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-04-04 14:51:23 UTC
  • Revision ID: james.westby@ubuntu.com-20050404145123-9py049eeelfymur8
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
; The GIMP -- an image manipulation program
 
2
; Copyright (C) 1995 Spencer Kimball and Peter Mattis
 
3
 
4
; This program is free software; you can redistribute it and/or modify
 
5
; it under the terms of the GNU General Public License as published by
 
6
; the Free Software Foundation; either version 2 of the License, or
 
7
; (at your option) any later version.
 
8
 
9
; This program is distributed in the hope that it will be useful,
 
10
; but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
; GNU General Public License for more details.
 
13
 
14
; You should have received a copy of the GNU General Public License
 
15
; along with this program; if not, write to the Free Software
 
16
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
;
 
18
;
 
19
; round-corners.scm   version 1.02   1999/12/21
 
20
;
 
21
; CHANGE-LOG:
 
22
; 1.00 - initial release
 
23
; 1.01 - some code cleanup, no real changes
 
24
;
 
25
; Copyright (C) 1997-1999 Sven Neumann <sven@gimp.org> 
 
26
;  
 
27
;
 
28
; Rounds the corners of an image, optionally adding a drop-shadow and
 
29
; a background layer
 
30
;
 
31
; The script works on RGB and grayscale images that contain only 
 
32
; one layer. It creates a copy of the image or can optionally work 
 
33
; on the original. The script uses the current background color to 
 
34
; create a background layer. It makes a call to the script drop-shadow.
 
35
;
 
36
; This script is derived from my script add-shadow, which has become 
 
37
; obsolet now.
 
38
 
 
39
 
 
40
 
 
41
(define (script-fu-round-corners img
 
42
                                 drawable
 
43
                                 radius
 
44
                                 shadow-toggle
 
45
                                 shadow-x
 
46
                                 shadow-y
 
47
                                 shadow-blur
 
48
                                 background-toggle
 
49
                                 work-on-copy)
 
50
  (let* ((shadow-blur (abs shadow-blur))
 
51
         (radius (abs radius))
 
52
         (diam (* 2 radius))
 
53
         (width (car (gimp-image-width img)))
 
54
         (height (car (gimp-image-height img)))
 
55
         (type (car (gimp-drawable-type-with-alpha drawable)))
 
56
         (image (cond ((= work-on-copy TRUE)
 
57
                       (car (gimp-image-duplicate img)))
 
58
                      ((= work-on-copy FALSE)
 
59
                       img)))
 
60
         (pic-layer (car (gimp-image-get-active-drawable image))))
 
61
 
 
62
  (cond ((= work-on-copy TRUE)
 
63
         (gimp-image-undo-disable image))
 
64
        ((= work-on-copy FALSE)
 
65
         (gimp-image-undo-group-start image)))
 
66
 
 
67
  ; add an alpha channel to the image
 
68
  (gimp-layer-add-alpha pic-layer)
 
69
  
 
70
  ; round the edges  
 
71
  (gimp-selection-none image)
 
72
  (gimp-rect-select image 0 0 radius radius CHANNEL-OP-ADD 0 0)
 
73
  (gimp-ellipse-select image 0 0 diam diam CHANNEL-OP-SUBTRACT TRUE 0 0)
 
74
  (gimp-rect-select image (- width radius) 0 radius radius CHANNEL-OP-ADD 0 0)
 
75
  (gimp-ellipse-select image (- width diam) 0 diam diam CHANNEL-OP-SUBTRACT TRUE 0 0)
 
76
  (gimp-rect-select image 0 (- height radius) radius radius CHANNEL-OP-ADD 0 0)
 
77
  (gimp-ellipse-select image 0 (- height diam) diam diam CHANNEL-OP-SUBTRACT TRUE 0 0)
 
78
  (gimp-rect-select image (- width radius) (- height radius)
 
79
                    radius radius CHANNEL-OP-ADD 0 0)
 
80
  (gimp-ellipse-select image (- width diam) (- height diam)
 
81
                       diam diam CHANNEL-OP-SUBTRACT TRUE 0 0)
 
82
  (gimp-edit-clear pic-layer)
 
83
  (gimp-selection-none image)
 
84
  
 
85
  ; optionally add a shadow
 
86
  (if (= shadow-toggle TRUE)
 
87
      (begin
 
88
        (script-fu-drop-shadow image
 
89
                               pic-layer
 
90
                               shadow-x
 
91
                               shadow-y
 
92
                               shadow-blur
 
93
                               '(0 0 0)
 
94
                               80
 
95
                               TRUE)
 
96
        (set! width (car (gimp-image-width image)))
 
97
        (set! height (car (gimp-image-height image)))))
 
98
      
 
99
  ; optionally add a background
 
100
  (if (= background-toggle TRUE)
 
101
      (let* ((bg-layer (car (gimp-layer-new image
 
102
                                            width
 
103
                                            height
 
104
                                            type
 
105
                                            "Background"
 
106
                                            100
 
107
                                            NORMAL-MODE))))
 
108
        (gimp-drawable-fill bg-layer BACKGROUND-FILL)
 
109
        (gimp-image-add-layer image bg-layer -1)
 
110
        (gimp-image-raise-layer image pic-layer)
 
111
        (if (= shadow-toggle TRUE)
 
112
            (gimp-image-lower-layer image bg-layer))))
 
113
 
 
114
; clean up after the script
 
115
  (cond ((= work-on-copy TRUE)
 
116
         (gimp-image-undo-enable image))
 
117
        ((= work-on-copy FALSE)
 
118
         (gimp-image-undo-group-end image)))
 
119
 
 
120
  (if (= work-on-copy TRUE)
 
121
      (gimp-display-new image))
 
122
  (gimp-displays-flush)))
 
123
 
 
124
(script-fu-register "script-fu-round-corners"
 
125
                    _"_Round Corners..."
 
126
                    "Round the corners of an image and optionally adds a drop-shadow and a background"
 
127
                    "Sven Neumann <sven@gimp.org>"
 
128
                    "Sven Neumann"
 
129
                    "1999/12/21"
 
130
                    "RGB GRAY"
 
131
                    SF-IMAGE       "Image"           0
 
132
                    SF-DRAWABLE    "Drawable"        0
 
133
                    SF-ADJUSTMENT _"Edge radius"     '(15 0 4096 1 10 0 1)
 
134
                    SF-TOGGLE     _"Add drop-shadow" TRUE
 
135
                    SF-ADJUSTMENT _"Shadow X offset" '(8 -4096 4096 1 10 0 1)
 
136
                    SF-ADJUSTMENT _"Shadow Y offset" '(8 -4096 4096 1 10 0 1)
 
137
                    SF-ADJUSTMENT _"Blur radius"     '(15 0 1024 1 10 0 1)
 
138
                    SF-TOGGLE     _"Add background"  TRUE
 
139
                    SF-TOGGLE     _"Work on copy"    TRUE)
 
140
 
 
141
(script-fu-menu-register "script-fu-round-corners"
 
142
                         _"<Image>/Script-Fu/Decor")