Resize image batch with a minimum of 10px transparency border |
Sep 27, 2011, 22:31
Post: #1
|
|||
|
|||
Resize image batch with a minimum of 10px transparency border
I'm writing a script to take all of the images in a folder and resize them so that the longest side is 290 pixels. Then it places this image onto a new transparent image that is 300x300 and saves it as a png.
At least that's what it's supposed to do. So far, all it does is the first part of resizing the image so that its longest length is 290 px. I don't get any errors when I run the script so I can't figure out why it's not working. Can anyone see what I've done wrong here? (define (batch-resize pattern) (let* ( ;Create a 300x300 image with a transparent background (filelist (cadr (file-glob pattern 1))) (finalImageWidth 300) (finalImageHeight 300) (finalImage) (finalImage (car (gimp-image-new finalImageWidth finalImageHeight RGBA ) ) ) (layer (car (gimp-layer-new theImage finalImageWidth finalImageHeight RGBA "layer 1" 0 NORMAL)) ) ) (while (not (null? filelist)) ;Resize all of the image files in the folder and add them as a layer to the 300x300 tranparent image ;with 10 pixels of padding on the longest side to show the transparency underneath (let* ( (filename (car filelist)) (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename))) (drawable1 (car (gimp-image-get-active-layer image))) (theWidth (car (gimp-drawable-width drawable1))) (theHeight (car (gimp-drawable-height drawable1))) ) (if (> theHeight theWidth) (gimp-image-scale-full image (+ theWidth (- 290 theHeight)) 290 INTERPOLATION-CUBIC) (gimp-image-scale-full image 290 (+ theHeight (- 290 theWidth)) INTERPOLATION-CUBIC) ) (let* ( (new-layer (car (gimp-image-get-layers image))) (gimp-image-add-layer theImage new-layer -1) (drawable2 (car (gimp-image-flatten theImage))) ) (file-png-save2 RUN-NONINTERACTIVE theImage drawable2 new.png new.png 0 0 0 0 0 0 0 0 1) (gimp-image-delete image) ) ) (set! filelist (cdr filelist)) ) ) ) |
|||
Sep 28, 2011, 17:59
Post: #2
|
|||
|
|||
RE: Resize image batch with a minimum of 10px transparency border
(Sep 28, 2011 06:27)paynekj Wrote: I think your problem is that you're not creating a new transparent layer: I switched out that line as you suggested but it didn't change anything. I noticed that where I was saving the file (file-png-save2), I was saving the drawable from the wrong image. But even after fixing THAT my result was the same (just resizing the original image to 290 px. I came to the conclusion that my script would have to be picked apart piece by piece to figure out what is wrong so I went with the previous suggestion to use ImageMagick. But thank you for your help anyway. |
|||
Sep 28, 2011, 18:02
(This post was last modified: Sep 28, 2011 18:03 by Bad Pie.)
Post: #3
|
|||
|
|||
RE: Resize image batch with a minimum of 10px transparency border
Replied to wrong comment. Guess I can't delete...
|
|||
Sep 28, 2011, 18:03
Post: #4
|
|||
|
|||
RE: Resize image batch with a minimum of 10px transparency border
(Sep 27, 2011 23:10)ofnuts Wrote: Why don't you look at ImageMagick for that. You would of course have to figure out a handful of parameters, but that would still be a lot simpler (and likely execute much faster) than using Gimp. 60 lines of code that didn't work to this using imagemagick: mogrify -path formatted -format png images/*.jpg -resize 290x290 -background transparent -gravity center -extent 300x300 images/*.jpg Works like a charm. Thanks for the suggestion. |
|||
« Next Oldest | Next Newest »
|
Possibly Related Threads... | |||||
Thread: | Author | Replies: | Views: | Last Post | |
Any plugin for open multiple image in paint.net | shinprog | 1 | 596 |
Oct 31, 2017 11:38 Last Post: paynekj |
|
Scale image to specific size | MattRothschild | 1 | 456 |
Sep 15, 2017 11:13 Last Post: ythgilb |
|
Dividing and printing a large image | RayArdia | 1 | 347 |
Aug 9, 2017 07:22 Last Post: ythgilb |
|
Late binding / COM for opening an image into GIMP? | i73 | 2 | 408 |
Aug 4, 2017 17:39 Last Post: i73 |
|
Batch create images from array | edmilner | 1 | 548 |
Jul 17, 2017 16:41 Last Post: ythgilb |