Sta*_*sor 5 linux scripting crop image-processing gimp
我有一堆屏幕截图,我想裁剪窗口边框.我想用脚本来裁剪它们.
我可以访问GIMP,但不能访问photoshop,所以我认为GIMP将是最好的工具.我以前没有使用GIMP编写脚本,因此我查找了一些GIMP裁剪脚本.我发现的那些都与我想要的相似,但并不完全.我认为将脚本改为我需要的是一件简单的事情.但由于我不熟悉脚本语言,因此证明比我想象的更难.我发现了一个巨大的自动裁剪脚本这里.有人可以帮助我根据我的需要定制它吗?
(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)))
Run Code Online (Sandbox Code Playgroud)
所有照片的整体尺寸都不相同.但它们在我想要裁剪的顶部,左侧,右侧和底部都具有相同数量的像素.因此,假设图像具有像素尺寸width
,height
我想t_junk
从顶部移除像素,b_junk
从底部移除像素,l_junk
从左侧移除像素,r_junk
从右移除像素.所以我希望新的图像尺寸为width - l_junk - r_junk
和height - t_junk - b_junk
.
我编写了一个自定义的GIMP脚本,它完全符合您的要求.只需将以下内容粘贴到文本文档中,然后使用.scm
扩展名将其保存在GIMP脚本文件夹中(可以在其中找到/创建路径Edit > Preferences > Folders > Scripts
):
(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()
Run Code Online (Sandbox Code Playgroud)
此脚本接收输入文件名,输出文件名和每侧剃掉的像素数.您可以从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)"
Run Code Online (Sandbox Code Playgroud)
或者您可以在Script-Fu控制台(Filters > Script-Fu > Console
)中运行它- 无论这样的操作系统如何:
(script-fu-wirebear-edger "C:\\Users\\You\\Desktop\\Images\\1.png"
"C:\\Users\\You\\Desktop\\Images\\1_edged.png" 10 30 25 5)
Run Code Online (Sandbox Code Playgroud)
为了在多个映像上运行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()
Run Code Online (Sandbox Code Playgroud)
该脚本采用搜索模式来匹配目标图像,添加到文件名的后缀和每个图像每侧的剃须像素数.您可以从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)"
Run Code Online (Sandbox Code Playgroud)
或者您可以在Script-Fu控制台(Filters > Script-Fu > Console
)中运行它- 无论这样的操作系统如何:
(script-fu-wirebear-batch-edger "C:\\Users\\You\\Desktop\\Images\\*.png"
"_edged" 10 30 25 5)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
8688 次 |
最近记录: |