0

我正在尝试准备一个用于自动调整图像文件大小的脚本。我找到了这个链接,但我不知道如何使用它。

任何人都可以提供一个我可以用作起点的工作脚本吗?

4

2 回答 2

2

以下函数调整图像大小:

(define (resize-image filename-in filename-out new-width new-height)
  (let* ((image    (car (gimp-file-load RUN-NONINTERACTIVE filename-in "")))
         (drawable (car (gimp-image-active-drawable image)))
        )

     (gimp-image-scale image new-width new-height)
     (gimp-file-save   RUN-NONINTERACTIVE image drawable filename-out "")
  )
)

现在,调整目录中所有 jpg 的大小:

(define (file-basename filename)
  (let*
    (
      (broken-up (strbreakup filename "."))
      (wo-last-r (cdr (reverse broken-up)))
      (wo-last   (reverse wo-last-r))
      (result "")
    )
    (while wo-last
      (set! result (string-append result (car wo-last) ))
      (set! wo-last (cdr wo-last))
      (if (> (length wo-last) 0) (set! result (string-append result ".")))
    )
    result
  )
)

(define (ex_09 file-pattern new-width new-height )

  (let* ( (filelist (cadr (file-glob file-pattern 1))))

    (while (not (null? filelist))
      (let* ( (cur-file  (car filelist)) )

        (resize-image 
           cur-file 
           (string-append (file-basename cur-file) "_resized.jpg")
           100 
           100
        )

        (set! filelist (cdr filelist))
      )
    )
  )
)

我想这就是你的答案。

于 2015-04-26T01:49:14.357 回答
0

代码来自这个地址。 http://www.adp-gmbh.ch/misc/tools/script_fu/ex_09.html

开箱即用,它对我不起作用。我做了一些改变:

在 file_basename.scm 文件中,我删除了一些我没有解决的东西。因此,调整大小的文件与原始文件在同一目录中创建:

(define (file-basename filename)
  (let*
     (
      (broken-up (strbreakup filename "."))
      (wo-last-r (cdr (reverse broken-up)))
      (wo-last   (reverse wo-last-r))
      (car broken-up) 
  )
)

在 ex_09.scm 文件中:我只使用了 new-width 和 new-height 变量。

(define (ex_09 file-pattern new-width new-height )
   (let* ( (filelist (cadr (file-glob file-pattern 1))))
     (while (not (null? filelist))
      (let* ( (cur-file  (car filelist)) )

      (resize-image 
        cur-file 
        (string-append (file-basename cur-file) "_resized.jpg")
        new-width
       new-height
    )

    (set! filelist (cdr filelist))
   )
  )
 )
 ) 

跳这有帮助!并感谢你 René Nyffenegger 的代码。:)

于 2016-04-22T17:41:28.253 回答