Hi all! I'm trying to work out a script that I can use to reduce the size of an image by half. However, I need this to work with images of different sizes, but I always want them to be scaled to half their size. I know that this code exists:
Code:
(gimp-image-scale image X Y)
But I've only ever used it for absolute sizes. How can I make it be relative? I'm assuming I'll need to get the current size of the image and then multiply those variables by 0.5, then use the variables in this command, but I'm having trouble finding any documentation about actually getting the layer sizes. Any help is appreciated!
Modder/Skinner at MarvelMods.com using GIMP to create, edit, and export textures and previews more efficiently.
See (gimp-image-width image) and (gimp-image-height image) to get the image width and height. Getting the sizes of layers is pointless here because you'll be scaling the image and not the layers.
The best way to find an answer to this kind of questions if to start the Scrip-fu console (Filters ➤ Script-fu ➤ Console) and then hit the Browse... button and try the terms in the search bar at the top left:
08-14-2022, 03:55 PM (This post was last modified: 08-14-2022, 04:03 PM by rich2005.)
Well, for a simplistic, single layer, plugin. The attached is the one I use to save on a bit of bandwidth. (followed by another plugin to export to a jpeg) It scales down two-thirds and adds a bit of sharpening. Not difficult to change the scaling factor., disable the sharpening.
I suppose the issue is your multi-layer images.
..and it is python, not script-fu
In the tools menu, no parameters.
If you have lots of images to scale, then I suggest the Gimp batch plugin BIMP or non-Gimp ImageMagick in a .bat file.
08-25-2022, 12:15 AM (This post was last modified: 08-25-2022, 12:20 AM by BaconWizard17.)
(08-14-2022, 03:15 PM)Ofnuts Wrote: See (gimp-image-width image) and (gimp-image-height image) to get the image width and height. Getting the sizes of layers is pointless here because you'll be scaling the image and not the layers.
The best way to find an answer to this kind of questions if to start the Scrip-fu console (Filters ➤ Script-fu ➤ Console) and then hit the Browse... button and try the terms in the search bar at the top left:
I've been trying to use these commands in the following script:
(gimp-image-scale image (/ (gimp-image-width image) 2) (/ (gimp-image-height image) 2))
But I keep getting an error that "argument 1 must be a number" for the division operations. Do I need to be assigning the value to a variable somehow?
Edit: managed to figure out how to assign variables and got this far, but now Gimp crashes when I use this:
(gimp-image-undo-group-start image)
(gimp-selection-none image)
(let*
(
(newWidth (gimp-image-width image))
(newHeight (gimp-image-height image))
)
(gimp-image-scale image (/ newWidth 2) (/ newHeight 2))
)
(gimp-displays-flush)
(gimp-image-undo-group-end image)
Modder/Skinner at MarvelMods.com using GIMP to create, edit, and export textures and previews more efficiently.
08-26-2022, 06:00 PM (This post was last modified: 08-26-2022, 06:12 PM by BaconWizard17.)
(08-25-2022, 07:47 AM)Kevin Wrote: You need to know that most GIMP functions in script-fu return a list, not a single value, so you need to extract the first value from the list:
(08-25-2022, 07:47 AM)Kevin Wrote: You need to know that most GIMP functions in script-fu return a list, not a single value, so you need to extract the first value from the list:
(08-25-2022, 07:47 AM)Kevin Wrote: You need to know that most GIMP functions in script-fu return a list, not a single value, so you need to extract the first value from the list: