【问题标题】:resize image using script-fu gimp使用 script-fu gimp 调整图像大小
【发布时间】:2015-07-04 03:11:28
【问题描述】:

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

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

【问题讨论】:

  • 为什么不直接使用 ImageMagick?它安装在大多数 Linux 发行版上,并且随时可用于所有其他优秀的操作系统和 Windows。 convert image.jpg -resize 256x200 result.jpg
  • 是的,但如果可以的话,我绝对建议您使用homebrew 安装它 - 或者 MacPorts,尽管我没有使用过后者。
  • 如果您使用的是 Mac,则可以使用 sips。在终端中输入man sips
  • sips -Z 256 image.jpg = resize image.jpg 所以两个维度都不超过 256 像素
  • @MarkSetchell 哇,太棒了!

标签: image autoresize gimp script-fu


【解决方案1】:

以下函数调整图像大小:

(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))
      )
    )
  )
)

我想这就是你的答案。

【讨论】:

  • 我可以调用这些函数吗?
【解决方案2】:

代码来自这个地址。 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 的代码。 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-04
    • 2018-09-30
    • 1970-01-01
    • 2018-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多