使用script-fu gimp调整图像大小

时间:2015-04-25 13:18:20

标签: image autoresize gimp script-fu

我正在尝试准备一个脚本来自动调整图像文件的大小。 我找到了这个LINK,但我无法弄清楚如何使用它。

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

2 个答案:

答案 0 :(得分: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))
      )
    )
  )
)

我认为这是你的答案。

答案 1 :(得分:0)

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

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

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

array<String^>^ strArray = gcnew array<String^>(10);
strArray[0] = gcnew String("dogs");
strArray[1] = gcnew String("cats");
strArray[2] = gcnew String("dogs");
strArray[3] = gcnew String("cats");
strArray[4] = gcnew String("dogs");
strArray[5] = gcnew String("cats");
strArray[6] = gcnew String("dogs");
strArray[7] = gcnew String("cats");
strArray[8] = gcnew String("dogs");
strArray[9] = gcnew String("cats");
bool found = false;
int index;
bool doThis = true;
String ^ text = u8"I have two dogs, three notdogs, also dogsikong, 5dogs, -dogs. DOGS, Dogs, DoGs, 33DoGs00";
for (int i = 0; i < 10; i += 2)
{
    int index = 0;
    while ((index = text->ToLower()->IndexOf(strArray[i]->ToLower(), index)) != -1)
    {
        doThis = true;
        // is there one more char?
        if (index + strArray[i]->Length < text->Length)
        {
            if (Char::IsLetter(text[index+strArray[i]->Length]))
                doThis = false;
        }
        // is there previous char?
        if (index > 0)
        {
            if (Char::IsLetter(text[index - 1]))
                doThis = false;
        }
        if (doThis)
            text = text->Substring(0, index) + strArray[i + 1] +
            text->Substring(index + strArray[i]->Length);
        Debug::WriteLine(text);
        index++;
    }
}

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

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

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