-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFU_save-as-jpg.scm
226 lines (195 loc) · 6.77 KB
/
FU_save-as-jpg.scm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
; FU_save-as-jpg.scm
; version 3.0 [gimphelp.org]
; last modified/tested by Paul Sherman
; 02/03/2014 on GIMP-2.8.10
; 27/10/2020 on GIMP-2.10.22
;
;==============================================================
;
; Installation:
; This script should be placed in the user or system-wide script folder.
;
; Windows Vista/7/8)
; C:\Program Files\GIMP 2\share\gimp\2.0\scripts
; or
; C:\Users\YOUR-NAME\.gimp-2.8\scripts
;
; Windows XP
; C:\Program Files\GIMP 2\share\gimp\2.0\scripts
; or
; C:\Documents and Settings\yourname\.gimp-2.8\scripts
;
; Linux
; /home/yourname/.gimp-2.8/scripts
;
; Linux system-wide
; /usr/share/gimp/2.0/scripts
;
;==============================================================
;
; LICENSE
;
; 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 3 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, see <http://www.gnu.org/licenses/>.
;
;==============================================================
; Original information
;
; Original script by Saul Goode
; script-fu-quick-jpeg-save.scm
; http://chiselapp.com/user/saulgoode/repository/script-fu/home
;==============================================================
(define (FU_save-as-jpg image)
(let* (
(nameparts (strbreakup (car (gimp-image-get-filename image)) "."))
(filename "")
)
(unless (and (> (length nameparts) 1)
(member (car (last nameparts)) '("jpg" "jpeg" "JPG" "JPEG"))
)
(set! nameparts (append (butlast nameparts) '("jpg")))
)
(set! filename (unbreakupstr nameparts "."))
(let* ( (buffer (car (gimp-edit-named-copy-visible image "jpg buffer")))
(new-image (car (gimp-edit-named-paste-as-new buffer)))
(layer (car (gimp-image-flatten new-image)))
)
(unless (zero? (car (gimp-image-base-type new-image)))
(gimp-image-convert-rgb new-image)
)
;(file-jpeg-save RUN-NONINTERACTIVE
; new-image
; layer
; filename
; filename
; 0.92 ; JPEG compression level
; 0.05 ; smoothing was0
; 1 ; optimize
; 0 ; progressive
; "" ; comment
; 2 ; subsmp (0-4) ; was0
; 1 ; baseline
; 0 ; restart
; 1 ;dct was 0
;)
(gimp-file-save RUN-NONINTERACTIVE
new-image
layer
filename
filename
)
(gimp-image-delete new-image)
(gimp-buffer-delete "jpg buffer")
(gimp-image-clean-all image)
(gimp-displays-flush)
(gc) ; garbage cleanup
)
)
)
(script-fu-register "FU_save-as-jpg"
"Fast Save as JPG"
"Fast Save the image as a JPG file\nWarning: Removes EXIF data. Only 1 . is allowed. Saves to same location as the original image and creates new file. Replaces extension with jpg. (eg. xcf to jpg). Save time in (Windows/IOS) folders does not update but can be found in the File>Open dialog. For more options and a proper file overwrite protected dialog, use the FILE > EXPORT AS menu item when saving as a JPG.\nfile:FU_save-as-jpg.scm"
"Paul Sherman"
"Paul Sherman"
"February 2014"
"*"
SF-IMAGE "Image" 0
)
(script-fu-menu-register "FU_save-as-jpg"
"<Image>/File/Save/"
)
;;================================================================================
(define (FU-slow-save-as-jpg image directory filenamegiven)
(let* (
(nameparts (strbreakup (car (gimp-image-get-filename image)) "."))
(filename "")
)
;(gimp-message directory)
;(gimp-message filenamegiven)
;(gimp-message filename)
(set! filename (string-append directory "/" filenamegiven ".jpg")) ; note have to use fwd slash as \" has a meaning in scheme
;(gimp-message filename)
;(gimp-message (car (last nameparts)))
;(gimp-message "Checks")
(if (equal? filenamegiven "")
(begin
(gimp-message "Filename must not be blank")
(quit)
)
(begin
;(gimp-message "Safe1")
)
)
(if (equal? directory "")
(begin
(gimp-message "Folder must be selected. Must not be blank")
(quit)
)
(begin
;(gimp-message "Safe2")
)
)
;(gimp-message "Checks done")
(let* (
(buffer (car (gimp-edit-named-copy-visible image "jpg buffer")))
(new-image (car (gimp-edit-named-paste-as-new buffer)))
(layer (car (gimp-image-flatten new-image)))
)
(unless (zero? (car (gimp-image-base-type new-image)))
(gimp-image-convert-rgb new-image)
)
(gimp-message (string-append "Final filename:" filename))
(file-jpeg-save RUN-NONINTERACTIVE
new-image
layer
filename
filename
0.92 ; JPEG compression level
0.05 ; smoothing was0
1 ; optimize
0 ; progressive
"" ; comment
2 ; subsmp (0-4) ; was0
1 ; baseline
0 ; restart
1 ;dct was 0
)
;(gimp-file-save RUN-NONINTERACTIVE
; new-image
; layer
; filename
; filename
;)
(gimp-image-delete new-image)
(gimp-buffer-delete "jpg buffer")
(gimp-image-clean-all image)
(gimp-displays-flush)
(gc) ; garbage cleanup
)
)
)
(script-fu-register "FU-slow-save-as-jpg"
"Slow Save as JPG"
"Slow Save the image as a JPG file. Requires a filename (without .jpg - will be added) and directory. \nWarning: Removes EXIF data. Only 1 . is allowed. Save Time in (Windows/IOS) folders does not update but can be found in the File>Open dialog. For more options and a proper file overwrite protected dialog, use the FILE > EXPORT AS menu item when saving as a JPG.\nfile:FU_save-as-jpg.scm"
"Paul Sherman"
"Paul Sherman"
"February 2014"
"*"
SF-IMAGE "Image" 0
SF-DIRNAME "Folder" ""
SF-STRING "Filename" "Fff"
)
(script-fu-menu-register "FU-slow-save-as-jpg"
"<Toolbox>/File/Save/"
)
;end of script