Automated batch xcf layer combining and png exporting - 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) +--- Thread: Automated batch xcf layer combining and png exporting (/Thread-Automated-batch-xcf-layer-combining-and-png-exporting) |
Automated batch xcf layer combining and png exporting - gimpler - 09-05-2021 Big favor to ask of you scripting/programming gurus. I have three directories full of Gimp XCF layers and need help automating the combining of them, and exporting the resulting images as PNGs. I'm agnostic to what language(s) are used, as long it'll run on a mac, specs below. So the idea is to sequentially loop through the three directories, load one respective XCF layer from each, and export the three-layer combination as a PNG in a 4th directory. The PNG filename could be a concatenation of the three XCF filenames used for each resultant image. Directory structure looks like this: ProjectName Layer1Files (top layer) A0.xcf A1.xcf A2.xcf A3.xcf A4.xcf Layer2Files (middle layer) B0.xcf B1.xcf B2.xcf B3.xcf B4.xcf Layer3Files (background layer) C0.xcf C1.xcf C2.xcf C3.xcf C4.xcf CombinedPngs (to be created) A0B0C0.png A0B0C1.png ... A0B0C4.png A0B1C0.png A0B1C1.png etc. And so forth until we get from A0B0C0.png all the way to A4B4C4.png. Mac is running Catalina 10.15.7 Gimp 2.10.24 per the Mac binary download. Python 2.7.16 per MacOS default. (Though I understand this version is obsolete.) Bash 3.2 is accessible (though zsh 5.7.1 is the default). Scheme I've see mentioned but know nothing about. Same with Fu. Happy to upgrade and/or install whatever's needed to get this done. THANK YOU to anyone willing to help with this! RE: Automated batch xcf layer combining and png exporting - rich2005 - 09-05-2021 Maybe one of the clever guys can come up with a Gimp script, I think ImageMagick (IM) more probable. IM7 reads a Gimp 2.10 file (at least it does here in linux) You could ask the question on the IM forum where there is a MacOS user. https://github.com/ImageMagick/ImageMagick/discussions Some clarification on file properties will help Are all the images the same size ? or do you need to place top / middle layers in specific places ? Images are to be stacked before writing to png, so these layers are partially transparent ? RE: Automated batch xcf layer combining and png exporting - Ofnuts - 09-05-2021 If instead of using XCF you use PNG, you can use ImageMagick's convert command in a Bash shell script (ie, the "Terminal" on OSX), then the whole thing becomes: Code: #! /bin/bash Code: ./generate /path/to/bottomDir /path/to/middleDir /path/to/topDir /path/to/outDir [attachment=6661]
PS:
RE: Automated batch xcf layer combining and png exporting - rich2005 - 09-05-2021 ImageMagick 7 reads .xcf here, so without any paths.to.. or loops or variables and assuming a stack of same size / no offsets / transparent top & mid and a background .xcf for a single combined.png Code: magick composite top.xcf mid.xcf temp.miff Edit, just the bare bones to avoid a conversion to png which AFAIK is needed for IM 6 which does not support the Gimp 2.10 .xcf image format. Edit again, I see Ofnuts has a ps about that. Good script for the IM toolbox. RE: Automated batch xcf layer combining and png exporting - gimpler - 09-06-2021 Wow, can't thank you guys enough. Here are some answers, results, and new questions. Rich: > Are all the images the same size ? The top layer is smaller than the middle which is smaller than the bottom. > or do you need to place top / middle layers in specific places ? They should just need to be stacked in order. I pre-aligned each layer to a common sized boundary. I wanted to simplify the automation effort to compositing only, and avoid any scripted image manipulation, at least for now. Some alignment woes described below. > Images are to be stacked before writing to png, so these layers are partially transparent ? Yes. Ofnuts: Awesome shell script and sample output! Can't tell you how exciting it is to have my output directory fill up with these combinations. Both: Yes ImageMagick 7.1.0-6 chokes on v2.10 XCFs. So I tried saving my XCF layers as pre-2.10. The only obvious method I found is to uncheck the last option when Saving, which leads to the Gimp complaint "Layer mode 'Normal' was added in GIMP 2.10". When I saved the layers like this, ImageMagick could combine them, but sometimes layer alignment was lost in the resulting PNGs. I spent a bunch of time going in and re-aligning each image layer in Gimp and saving as pre-2.10 XCFs. But somehow the results were inconsistent. So I ended up just going with PNG layers, which all aligned correctly when combined with the script. Questions: Is there a better way to enforce layer alignment than pre-aligning each layer to a common sized boundary? (I never paid much attention to this, it always just worked right when doing things manually in Gimp.) What's the preferred way to save v2.8 XCFs? Gimp doc says PNG is lossless here, but when exporting to PNG, Gimp offers a compression slider, defaulting to 9. Is 9 lossless? Or maybe 0? RE: Automated batch xcf layer combining and png exporting - rich2005 - 09-06-2021 Quote:What's the preferred way to save v2.8 XCFs? The Gimp save dialogue has a message at the bottom of its window with information on compatibility. Most often it is the layer mode which has a default / legacy switch but the Bit depth also comes into play in Image -> Precision Check that 8 bit & perceptual(sRGB) is set. [attachment=6662] Shame the MacOS IM v7 does not rcognise Gimp 2.10 .xcf however seems pointless to me to re-save all those .xcf to an earlier format. Export what you have straight to .png PNG is lossless, the compression slider just applies the degree of compression. Lower compression = faster loading. Quote: Is there a better way to enforce layer alignment than pre-aligning each layer to a common sized boundary? (I never paid much attention to this, it always just worked right when doing things manually in Gimp.) I am a great believer in keep things as simple as possible. You can place images in IM using offsets, not sure how well that works with the IM composite command. An alternative is resize the top/mid images to background size using IM in the script. Edit: I had a look at offsets for the composite command and not able to find anything slick. Again this is just an example for a single set of files, add your own loops, variables etc. but for a simple linear sequence this: Make an empty canvas - add the top image with offsets - add the middle image with offsets - combine with the background. Offsets are top-left-corner of an image. Code: magick -size 500x500 canvas:transparent canvas.miff Still using the .xcf's from yesterday, the .miff files are IM's own format. Maybe ok if all the offsets are the same, if they vary between sets of images then I think your original is still the easiest way. Gets this https://i.imgur.com/kYUfrW1.jpg dotted in the top/mid image sizes RE: Automated batch xcf layer combining and png exporting - gimpler - 09-08-2021 Thanks for the follow up Rich. I have now implemented all your suggestions! |