Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 使用脚本fu gimp调整图像大小_Image_Autoresize_Gimp_Script Fu - Fatal编程技术网

Image 使用脚本fu gimp调整图像大小

Image 使用脚本fu gimp调整图像大小,image,autoresize,gimp,script-fu,Image,Autoresize,Gimp,Script Fu,我正在准备一个脚本,用于自动调整图像文件的大小。 我找到了这个,但我不知道如何使用它 任何人都可以提供一个工作脚本,我可以将其用作起点?以下函数用于调整图像大小: (define (resize-image filename-in filename-out new-width new-height) (let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename-in ""))) (drawable (ca

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


任何人都可以提供一个工作脚本,我可以将其用作起点?

以下函数用于调整图像大小:

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

我想这就是你的答案。

代码来自这个地址。

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

在文件_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文件中: 我只是使用了新的宽度和高度变量

(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))
   )
  )
 )
 ) 
跳这个有帮助! 谢谢你的代码。
:)

为什么不直接使用ImageMagick?它安装在大多数Linux发行版上,可用于所有其他良好的操作系统和Windows
convert image.jpg-resize 256x200 result.jpg
是的,但如果可以的话,我绝对建议您使用
homebrew
或MacPorts安装,尽管我没有使用后者。如果您在Mac上,您可以使用
sips
。在终端中键入
man sips
sips-Z 256 image.jpg
=调整
image.jpg的大小,这样两个维度都不超过256pixels@MarkSetchell哇,太棒了!我可以调用这些函数吗?