linux– 如何使用GIMP编写自定义自动裁剪脚本?

linux– 如何使用GIMP编写自定义自动裁剪脚本?,第1张

概述我有一堆屏幕截图,我想裁剪窗口边框.我想用脚本来裁剪它们.我可以访问GIMP,但不能访问photoshop,所以我认为GIMP将是最好的工具.我以前没有使用GIMP编写脚本,因此我查找了一些GIMP裁剪脚本.我发现的那些都与我想要的相似,但并不完全.我认为将脚本改为我需要的是一件简单的事情.但由于我不熟悉脚本语言,因此证明比我想象的更难.我找到了一个很棒的自

我有一堆屏幕截图,我想裁剪窗口边框.我想用脚本来裁剪它们.

我可以访问GIMP,但不能访问photoshop,所以我认为GIMP将是最好的工具.我以前没有使用GIMP编写脚本,因此我查找了一些GIMP裁剪脚本.我发现的那些都与我想要的相似,但并不完全.我认为将脚本改为我需要的是一件简单的事情.但由于我不熟悉脚本语言,因此证明比我想象的更难.我找到了一个很棒的自动裁剪脚本here.有人可以帮我定制它以满足我的需求吗?

    (define (script-fu-rs-center-crop filename outfilename wIDth height)  (let* ((image (car (gimp-file-load RUN-NONINteraCTIVE filename filename)))          (drawable (car (gimp-image-get-active-layer image))))          (let* ((original-wIDth (car (gimp-image-wIDth image)))               (original-height (car (gimp-image-height image)))               (new-wIDth original-wIDth)               (new-height original-height)               (offset-x 0)               (offset-y 0))               (if (<= (/ original-wIDth original-height) (/ wIDth height))                   (gimp-image-crop image original-wIDth (* original-wIDth (/ height wIDth)) 0 (/ (- original-height (* original-wIDth (/ height wIDth))) 2) )                   (gimp-image-crop image (* original-height (/ wIDth height)) original-height (/ (- original-wIDth (* original-height (/ wIDth height))) 2) 0)               )           )  (set! drawable (car (gimp-image-get-active-layer image)))(gimp-file-save RUN-NONINteraCTIVE image drawable outfilename outfilename)     (gimp-image-delete image)))

所有照片的整体尺寸都不相同.但它们在我想要裁剪的顶部,左侧,右侧和底部都具有相同数量的像素.因此,假设图像具有像素尺寸宽度和高度,我想从顶部移除t_junk像素,从底部移除b_junk像素,从左侧移除l_junk像素,从右移除r_junk像素.所以我希望新的图像尺寸为宽度 – l_junk – r_junk和height – t_junk – b_junk.最佳答案Edger Script

我编写了一个自定义的GIMP脚本,它完全符合您的要求.只需将以下内容粘贴到文本文档中,然后将其以.scm扩展名保存在GIMP脚本文件夹中(可以在编辑>首选项>文件夹>脚本中找到/创建路径):

(define (script-fu-wirebear-edger filename outfilename top right bottom left)(let* (    (img (car (gimp-file-load RUN-NONINteraCTIVE filename filename)))    (owIDth (car (gimp-image-wIDth img)))    (oheight (car (gimp-image-height img)))    (wIDth (- owIDth (+ right left)))    (height (- oheight (+ top bottom)))      )   ;Crop Image    (gimp-image-crop img wIDth height left top)   ;Save    (gimp-file-save RUN-NONINteraCTIVE        img        (car (gimp-image-active-drawable img))        outfilename        outfilename)   ;Cleanup    (gimp-image-delete img)))(script-fu-register "script-fu-wirebear-edger"    "Edger"    "Removes junk from the edges of an image"    "Chris Kent"    "WireBear.com"    "August 2011"    "RGB* GRAY*"    Sf-string "filename" ""    Sf-string "Outputfilename" ""    SF-VALUE "topEdge" "0"    SF-VALUE "RightEdge" "0"    SF-VALUE "BottomEdge" "0"    SF-VALUE "leftEdge" "0")script-fu-wirebear-edger()

此脚本接收输入文件名,输出文件名和每侧剃掉的像素数.您可以从windows运行该命令(假设您已将GIMP设置为环境变量),这样(确保如图所示转义特殊字符并将所有字符放在一行上):

C:>gimp-2.6 -i -c -b   "(script-fu-wirebear-edger \"C:\Users\You\Desktop\Images\1.png\"    \"C:\Users\You\Desktop\Images\1_edged.png\" 10 30 25 5)"   -b "(gimp-quit 0)"

或者您可以在Script-Fu控制台(过滤器> Script-Fu>控制台)中运行它 – 无论这样的 *** 作系统如何:

(script-fu-wirebear-edger "C:\Users\You\Desktop\Images\1.png" "C:\Users\You\Desktop\Images\1_edged.png" 10 30 25 5)

批处理Edger脚本

为了在多个映像上运行Edger脚本,您可以将以下脚本与上面的脚本结合使用(您将在Scripts文件夹中同时使用这两个脚本):

(define (script-fu-wirebear-batch-edger pattern outsuffix top right bottom left)(let* (    (fileList (cadr (file-glob pattern 1)))    (filename "")    (outfn "")      )    (while (not (null? fileList))        (set! filename (car fileList))        (set! outfn             (string-append                 (string-append                     (substring filename 0 (- (string-length filename) 4))                    outsuffix)                (substring filename (- (string-length filename) 4))            )        )        (script-fu-wirebear-edger filename outfn top right bottom left)        (set! fileList (cdr fileList))    )))(script-fu-register "script-fu-wirebear-batch-edger"    "Batch Edger"    "Removes junk from the edges of a serIEs of images"    "Chris Kent"    "WireBear.com"    "August 2011"    "RGB* GRAY*"    Sf-string "Pattern" "*.png"    Sf-string "OutputSuffix" "_edged"    SF-VALUE "topEdge" "0"    SF-VALUE "RightEdge" "0"    SF-VALUE "BottomEdge" "0"    SF-VALUE "leftEdge" "0")script-fu-wirebear-batch-edger()

该脚本采用搜索模式来匹配目标图像,添加到文件名的后缀和每个图像每侧的剃须像素数.您可以从windows运行该命令(假设您已将GIMP设置为环境变量),这样(确保如图所示转义特殊字符并将所有字符放在一行上):

C:>gimp-2.6 -i -c -b   "(script-fu-wirebear-batch-edger \"C:\Users\You\Desktop\Images\*.png\"    \"_edged\" 10 30 25 5)"   -b "(gimp-quit 0)"

或者您可以在Script-Fu控制台(过滤器> Script-Fu>控制台)中运行它 – 无论这样的 *** 作系统如何:

(script-fu-wirebear-batch-edger "C:\Users\You\Desktop\Images\*.png""_edged" 10 30 25 5)
总结

以上是内存溢出为你收集整理的linux – 如何使用GIMP编写自定义自动裁剪脚本?全部内容,希望文章能够帮你解决linux – 如何使用GIMP编写自定义自动裁剪脚本?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/1046793.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存