René Nyffenegger's collection of things on the web | |
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
Script-fu example 10: Resizing images and keeping the aspect ratio | ||
The following function resizes an image while it preserves its aspect ratio. This is different from the function resize-image which only resizes the image but doesn't
keep the aspect ratio. (See also resize-image-keep-ratio.
resize_image.scm
(define (resize-image-keep-ratio 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))) (cur-width (car (gimp-image-width image))) (cur-height (car (gimp-image-height image))) (ratio (min (/ new-width cur-width) (/ new-height cur-height))) (width (* ratio cur-width)) (height (* ratio cur-height)) ) (gimp-image-scale image width height) (gimp-file-save RUN-NONINTERACTIVE image drawable filename-out "") ) ) c:\> start gimp-2.2.exe -d -i -b "(resize-image-keep-ratio \"c:\\temp\\ex_10.jpg\" \"c:\\temp\\ex_10_resized.jpg\" 100 100)" "(gimp-quit 0)"
See also other examples
|