首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GIMP方案错误:(:1) eval: unbound变量: strbreakup

GIMP方案错误:(:1) eval: unbound变量: strbreakup
EN

Stack Overflow用户
提问于 2018-04-05 19:42:32
回答 1查看 2.5K关注 0票数 1

我在github上找到了这个很棒的脚本,并在Windows 7上成功地与GIMP一起使用。我最近升级到了Windows 10,现在它不能工作了。我得到以下错误:

执行script-fu批处理智能调整程序时出错:

错误:(:1) eval: unbound变量: strbreakup

以下是代码:

代码语言:javascript
复制
; https://github.com/per1234/batch-smart-resize
(define (script-fu-batch-smart-resize sourcePath destinationPath filenameModifier outputType outputQuality maxWidth maxHeight pad padColor . JPEGDCT)
  (define (smart-resize fileCount sourceFiles)
    (let*
      (
        (filename (car sourceFiles))
        (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
      )
      (gimp-image-undo-disable image)

      ;crop to mask if one exists
      (if (not (= (car (gimp-layer-get-mask (car (gimp-image-get-active-layer image)))) -1)) (plug-in-autocrop RUN-NONINTERACTIVE image (car (gimp-layer-get-mask (car (gimp-image-get-active-layer image))))))

      ;image manipulation
      (let*
        (
          ;get cropped source image dimensions
          (sourceWidth (car (gimp-image-width image)))
          (sourceHeight (car (gimp-image-height image)))

          ;don't resize image to larger than original dimensions
          (outputMaxWidth (if (< sourceWidth maxWidth) sourceWidth maxWidth))
          (outputMaxHeight (if (< sourceHeight maxHeight) sourceHeight maxHeight))

          (outputWidth (if (< (/ sourceWidth sourceHeight) (/ outputMaxWidth outputMaxHeight)) (* (/ outputMaxHeight sourceHeight) sourceWidth) outputMaxWidth))
          (outputHeight (if (> (/ sourceWidth sourceHeight) (/ outputMaxWidth outputMaxHeight)) (* (/ outputMaxWidth sourceWidth) sourceHeight) outputMaxHeight))
        )
        (gimp-image-scale image outputWidth outputHeight)  ;scale image to the output dimensions

        ;pad
        (if (= pad TRUE)
          (begin
            (gimp-image-resize image maxWidth maxHeight (/ (- maxWidth outputWidth) 2) (/ (- maxHeight outputHeight) 2))  ;resize canvas to to maximum dimensions and center the image

            ;add background layer
            (let*
              (
                (backgroundLayer (car (gimp-layer-new image maxWidth maxHeight RGB-IMAGE "Background Layer" 100 NORMAL-MODE)))  ;create background layer
              )
              (let*
                (
                  (backgroundColor (car (gimp-context-get-background)))  ;save the current background color so it can be reset after the padding is finished
                )
                (gimp-context-set-background padColor)  ;set background color to the padColor
                (gimp-drawable-fill backgroundLayer 1)  ;Fill the background layer with the background color. I have to use 1 instead of FILL-BACKGROUND because GIMP 2.8 uses BACKGROUND-FILL.
                (gimp-context-set-background backgroundColor)  ;reset the background color to the previous value
              )
              (gimp-image-insert-layer image backgroundLayer 0 1)  ;add background layer to image
            )
          )
        )
      )

      (gimp-image-flatten image)  ;flatten the layers


      (let*
        (
          ;format filename - strip source extension(from http://stackoverflow.com/questions/1386293/how-to-parse-out-base-file-name-using-script-fu), add filename modifier and destination path
          (outputFilenameNoExtension
            (string-append
              (string-append destinationPath "/")
              (unbreakupstr
                (reverse
                  (cdr
                    (reverse
                      (strbreakup
                        (car
                          (reverse
                            (strbreakup filename (if isLinux "/" "\\"))
                          )
                        )
                        "."
                      )
                    )
                  )
                )
                "."
              )
              filenameModifier
            )
          )
        )

        ;save file
        (cond
          ((= outputType 0)
            (let*
              (
                (outputFilename (string-append outputFilenameNoExtension ".png"))  ;add the new extension
              )
              (file-png-save RUN-NONINTERACTIVE image (car (gimp-image-get-active-drawable image)) outputFilename outputFilename FALSE 9 TRUE FALSE FALSE TRUE TRUE)
            )
          )
          ((= outputType 1)

            (let*
              (
                (outputFilename (string-append outputFilenameNoExtension ".jpg"))  ;add the new extension
              )
              (file-jpeg-save RUN-NONINTERACTIVE image (car (gimp-image-get-active-drawable image)) outputFilename outputFilename (/ outputQuality 100) 0 TRUE TRUE "" 2 TRUE 0 (if (null? JPEGDCT) 0 (car JPEGDCT)))
            )
          )
          (else
            (let*
              (
                (outputFilename (string-append outputFilenameNoExtension ".gif"))  ;add the new extension
              )
              (gimp-image-convert-indexed image 1 0 256 TRUE TRUE "")
              (file-gif-save RUN-NONINTERACTIVE image (car (gimp-image-get-active-drawable image)) outputFilename outputFilename FALSE FALSE 0 0)
            )
          )
        )
      )
      (gimp-image-delete image)
    )
    (if (= fileCount 1) 1 (smart-resize (- fileCount 1) (cdr sourceFiles)))  ;determine whether to continue the loop
  )

  ;detect OS type(from http://www.gimp.org/tutorials/AutomatedJpgToXcf/)
  (define isLinux
    (>
      (length (strbreakup sourcePath "/" ) )  ;returns the number of pieces the string is broken into
      (length (strbreakup sourcePath "\\" ) )
    )
  )
  (define sourceFilesGlob (file-glob (if isLinux (string-append sourcePath "/*.*") (string-append sourcePath "\\*.*")) 0))
  (if (pair? (car (cdr sourceFilesGlob)))  ;check for valid source folder(if this script is called from another script they may have passed an invalid path and it's much more helpful to return a meaningful error message)
    (smart-resize (car sourceFilesGlob) (car (cdr sourceFilesGlob)))
    (error (string-append "Invalid Source Folder " sourcePath))
  )
)
;dialog
(script-fu-register
  "script-fu-batch-smart-resize"  ;function name
  "batch-smart-resize"  ;menu label
  "Crop to layer mask, resize within maximum dimensions, and pad to max dimensions(optional)"  ;description
  "per1234"  ;author
  ""  ;copyright notice
  "2015-10-02"  ;date created
  ""  ;image type
  SF-DIRNAME "Source Folder" ""  ;sourcePath
  SF-DIRNAME "Destination Folder" ""  ;destinationPath
  SF-STRING "Output Filename Modifier(appended)" ""  ;filenameModifier
  SF-OPTION "Output Type" '("PNG" "JPEG" "GIF")  ;outputType
  SF-VALUE "Output Quality(JPEG only) 0-100" "90"  ;outputQuality
  SF-VALUE "Max Width" "1500"  ;maxWidth
  SF-VALUE "Max Height" "1500"  ;maxHeight
  SF-TOGGLE "Pad" TRUE  ;pad
  SF-COLOR "Padding Color" "white"  ;padColor
)
(script-fu-menu-register "script-fu-batch-smart-resize"
                         "<Image>/Tools")  ;menu location

我已经试过了所有我能在网上找到的东西,这是我最后的选择。我是否遗漏了Windows 7版本中可接受的语法,而在Windows 10版本中则不是这样?

谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-05 20:21:56

strbreakup定义为script-fu-compat.init in /usr/share/gimp/2.0/scripts (或C:\Program Files\GIMP 2\share\gimp\2.0\scripts for /usr/share/gimp/2.0/scripts)。该文件是否存在并完成(我的工作版本中有372行)?

编辑:注释摘要: Gimp没有查看它的标准scripts目录。上面的目录应该在Edit>Preferences>Folders>Scripts中列出。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49680302

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档