Resize all layers in script-fu - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP) +---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions) +---- Thread: Resize all layers in script-fu (/Thread-Resize-all-layers-in-script-fu) |
Resize all layers in script-fu - BaconWizard17 - 10-23-2022 Hi all! I've got a bit of a question about scripting. I'm trying to get a script to resize two both layers of an image instead of just the active one, but I'm not entirely sure how to go about doing that. First, I set up the image with this script: Code: (define (script-fu-mua-xml2-single-preview) I then do some work with that image and export it. After that, I want to double the width of the image by resizing the canvas. In doing so, I want all the layers to resize as well. Here's what I have so far: Code: (define (script-fu-mua-xml2-double-preview image layer) I cut out some extra stuff from both scripts like some codes to add vertical/horizontal guides in various places which all works the way I want it to. Generally, I have the top layer selected when I execute the second script, so the top layer is resized, but the bottom one isn't. I want it to be able to resize both layers to the image size, though, regardless of which one I have actively selected (if it's possible to do so). How do I go about doing that? RE: Resize all layers in script-fu - programmer_ceds - 10-23-2022 (10-23-2022, 04:08 PM)BaconWizard17 Wrote: Hi all! I've got a bit of a question about scripting. I'm trying to get a script to resize two both layers of an image instead of just the active one, but I'm not entirely sure how to go about doing that. First, I set up the image with this script: If you want to resize all of the layers use gimp-image-get-layers to get the number of layers and an array of layers. See Filters/Python-Fu/Console/Browse and type layers into the search box. Simply call gimp-layer-resize-to-image-size for each of the layers. RE: Resize all layers in script-fu - Ofnuts - 10-23-2022 (10-23-2022, 06:42 PM)programmer_ceds Wrote: See Filters/Python-Fu/Console/Browse and type layers into the search box. I think you meant Filters ➤ Script-fu ➤ Console ➤ Browse (even if I'm pretty sure the OP would be more comfortable doing the whole thing in Python). RE: Resize all layers in script-fu - programmer_ceds - 10-23-2022 (10-23-2022, 07:17 PM)Ofnuts Wrote: I think you meant Filters ➤ Script-fu ➤ Console ➤ Browse (even if I'm pretty sure the OP would be more comfortable doing the whole thing in Python). It doesn't actually matter how you get at the PDB it still shows the functions in the Script-Fu form with hyphens rather than underscores. RE: Resize all layers in script-fu - BaconWizard17 - 10-24-2022 I am more familiar with Python coding than I am with Scheme, but I've gotten this far with Scheme so I may as well finish the job. I'm assuming that using gimp-image-get-layers would just be: Code: (let* (I haven't done anything with multiple return values before, but from some quick googling this seems to be the right way to do that) I haven't been able to find terrific documentation on looping in Scheme. Based on what I've seen, I was able to put this together, but it doesn't resize any layers Code: (define layer-resize Any insight? RE: Resize all layers in script-fu - programmer_ceds - 10-25-2022 (10-24-2022, 09:59 PM)BaconWizard17 Wrote: I am more familiar with Python coding than I am with Scheme, but I've gotten this far with Scheme so I may as well finish the job. I'm assuming that using gimp-image-get-layers would just be:You could try something like: Code: (set! x 0) RE: Resize all layers in script-fu - BaconWizard17 - 10-26-2022 (10-25-2022, 07:19 AM)programmer_ceds Wrote:(10-24-2022, 09:59 PM)BaconWizard17 Wrote: I am more familiar with Python coding than I am with Scheme, but I've gotten this far with Scheme so I may as well finish the job. I'm assuming that using gimp-image-get-layers would just be:You could try something like: This got me on the right path (though I had to use "define" instead of "set!" in the first line), but it seems that it doesn't like how I'm assigning the "num_layers" and "layer_ids" variables. That makes me assume my syntax is incorrect there. I haven't been able to find anything that uses gimp-image-get-layers, so I can't find how I'm supposed to actually get the values. RE: Resize all layers in script-fu - teapot - 10-26-2022 (10-26-2022, 09:11 PM)BaconWizard17 Wrote: it seems that it doesn't like how I'm assigning the "num_layers" and "layer_ids" variables. That makes me assume my syntax is incorrect there. I haven't been able to find anything that uses gimp-image-get-layers, so I can't find how I'm supposed to actually get the values. You are using cdr to get the layer ids, use cadr. Here's my go: Code: ; Testing resize layers to image size RE: Resize all layers in script-fu - BaconWizard17 - 10-26-2022 (10-26-2022, 11:00 PM)teapot Wrote:(10-26-2022, 09:11 PM)BaconWizard17 Wrote: it seems that it doesn't like how I'm assigning the "num_layers" and "layer_ids" variables. That makes me assume my syntax is incorrect there. I haven't been able to find anything that uses gimp-image-get-layers, so I can't find how I'm supposed to actually get the values. That worked perfectly! Thank you for the help! I noticed you used "let" instead of "let*". Both variations work for me, but is there a difference between the two? RE: Resize all layers in script-fu - teapot - 10-26-2022 (10-26-2022, 11:23 PM)BaconWizard17 Wrote:(10-26-2022, 11:00 PM)teapot Wrote:(10-26-2022, 09:11 PM)BaconWizard17 Wrote: it seems that it doesn't like how I'm assigning the "num_layers" and "layer_ids" variables. That makes me assume my syntax is incorrect there. I haven't been able to find anything that uses gimp-image-get-layers, so I can't find how I'm supposed to actually get the values. Your'e welcome.. let* when the order of evaluation matters e.g. when one variable uses another one. let when it doesn't matter. http://computer-programming-forum.com/40-scheme/540d79041dafb466.htm |