Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script "slice using guides" and "png export"
#6
(10-25-2022, 09:29 AM)Lamidetlm Wrote: thank you for your responsiveness Smile
(10-24-2022, 04:19 PM)Ofnuts Wrote: Merging all layers can be done with gimp-image-flatten (but this also removes any transparency).
Too bad I really need transparency..

(10-24-2022, 04:19 PM)Ofnuts Wrote: The equivalent to the "slice using guides" in the UI is plugin-guillotine
Good thing , it's work !


(Honestly, I don't really understand what I'm doing. I'm not a coder.)

Quote:gimp-file-save saves the image in whatever format is given as an extension (so as PNG if the file names ends with .png). You can also for a PNG save with gimp-png-save or file-png-save2. Note that all the save operation to "flat" files (PNG, JPG...) only apply to the  specified layer.


I tried the different "png export" the only one that does not crash my code is "file-png-save-defaults".
But it gives me a script that runs in a loop and always outputs .gimp files and not .png files

Code:
(define (script-fu-save-png Image layer)
 (let* ((i (car (gimp-image-list)))
        (image))
   (while (> i 0)
     (set! image (vector-ref (cadr (gimp-image-list)) (- i 1)))
     (plug-in-guillotine RUN-NONINTERACTIVE
                     image
                     (car (gimp-image-merge-visible-layers image 1))
                )
                
     (file-png-save-defaults RUN-NONINTERACTIVE
                     image
                
                     (car (gimp-image-merge-visible-layers image 1))                      
                     (car (gimp-image-get-filename image))
                     (car (gimp-image-get-filename image)))

     (gimp-image-clean-all image)
     (set! i (- i 1)))))



(script-fu-register
  "script-fu-save-png"
  "<Image>/File/Save PNG & Exit"
  "Save PNG file and exit GIMP."
  "kes"
  "kes"
  "October 2017"
  "RGB*, GRAY*, INDEXED*"
  SF-IMAGE         "Image" 0
  SF-DRAWABLE   "Layer" 1
)

Quote:This said, I have the gut feeling that this is the wrong way .... layers (so this would be you "flatten, slice and save").
I create textures that are used in several projects. On a large image of 2048*1536 pixels.
The obtimal format for the engine is 512*512px, so I cut the whole thing for each export.

Each project involves small variations / retouching of this image.

Working on the set is very convenient in my case.

But exporting 10 images manually each time is unnecessarily painful.

Your scripts seem rather suitable yes.
I would be interested in seeing this, at least to understand the structure of the code.
If you want to share I take it with joy  Big Grin

The ofn-tiles script can be found there (it's written in Python, but your Windows Gimp has built-in Python support). See bottom of linked page for installation instructions. See HTML doc inside the ZIP.

You can use it by either specifying the tile size (512x512) or the row and columns (3 rows and 4 columns).
Reply


Messages In This Thread
RE: Script "slice using guides" and "png export" - by Ofnuts - 10-26-2022, 07:21 AM

Forum Jump: