Look at this photo.
It seems a little fat? In my previouse post, I had introduced the resize script. The method resize script used was a direct resize. If the ratio of the original file is not same as the target file, the file will get into distortion. I write a script can automatically crop the image to the target ratio. The new result is here.
This script crop the top and bottom part of the image, so the result image can fit my favorite ratio, compare the images below.
The girl become slim again.
Now let’s see the gimp script rs-center-crop.scm:
(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)))
set str=%1 set str=%str:\=/% set str2=%2 set str2=%str2:\=/% "D:\Program Files\GIMP-2.0\bin\gimp-2.6.exe" -i --verbose -b "(script-fu-rs-center-crop \"%str%\" \"%str2%\" 200 120)" -b "(gimp-quit 0)"
In the last line, “200″ and “100″ is the target ratio. Because my file will resize to 200*120, so I set the ratio as 200 and 120. At last, we add it into the context menu, we write the reg file rs-center-crop.reg.
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\RSGimpCrop] @="Crop as 200*120" [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\RSGimpCrop\command] @="F:\\rocksun\\gimp-script\\rs-center-crop\\rs-center-crop.bat \"%1\" \"%1\""
All files you can download or checkout with subversion from http://gimp-script.googlecode.com/svn/trunk/rs-center-crop/ . I create this project to collect and produce gimp script, you can join it.