Create xcf with multiple layers

Hello,

I have been able to create a xcf to edit in gimp using ‘gmic img.jpg -o img.xcf’ and that works fine.

I would like to create now a xcf file with multiple layers, each containing an image specified in the command line. Something like,

gmic img1.jpg img2.png img3.pgm -o img.xcf

where img1.jpg goes on the top layer, img2.png is assigned to the middle layer, and img3.pgm into the bottom layer. When I tried, img.xcf contains only one image, the first one, img1.jpg.

Please let me know if and how to accomplish this using gmic. I know gimp has a batch mode that can be used to create this but I would rather create the xcf in my pipeline that is already using gmic. Iam using Version 1.7.9.

Thanks,

  • Alex
1 Like

A while back I asked the same question. Seems not possible at the moment:

https://discuss.pixls.us/t/is-it-possible-to-output-image-list-as-layers-in-xcf-file/3229/2?u=stonefree

Thanks for the input. Were you able to create a script for that? I am not keen into learning gimp lisp-like scripting, but will do if no other alternative pans out, and post here.

No, I ended up with a bash script that creates two png files that I “Open as Layers” in gimp. Not ideal, but OK.

https://github.com/4232/quinema/blob/master/quinema-sombra#L84
line 84

Awesome bazza! That’s a good starting point. Python is much preferred. I will recraft your piece and post back here. Many thanks.

is python inside program in bash

G’MIC actually does not manage .xcf files, unfortunately.
If you try to read/write a .xcf file, G’MIC actually uses a fallback to ImageMagick’s convert. :wink:

Anyway, you can still use multi-page .tiff files to write multiple layers in a single file. GIMP 2.9 is able to read multi-page .tiff, the only thing you cannot do is setting the blending mode for each layer.

Something like that worked for me:

$ gmic -sp lena -sp tiger -o gmic_multilayers.tiff,uchar,none,1
2 Likes

Oh nice! I did not realize that I could use multilayer .tiff. This is now the bash script that I use as a final sharpening after resize:

#!/bin/bash
# Sharpening for web workflow:
# 1. Develop the photo at twice the desired final size (Darktable, RawTherapee, etc.).
# 2. "Over-sharpen" a duplicate of the image using twice the strength in "darkness", compared to "lightness".
# 3. Resize original image and sharpened image to final dimensions (50% of original).
# 4. Output original and sharpened images as layers in a tiff file.
# 5. Open in gimp and adjust opacity of sharpened layer (or enhance sharpness where required by painting with mask)
# 6. Export to jpeg.
# This scrip does steps 2 to 4.

# Set the field separator to handle filenames with spaces
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

# List of image files to process
file_list=$(find . -name '*.tif')

for file in $file_list; do

# Sharpen, then resize sharpened and original images and output both
	gmic -input "$file" --_fx_unsharp 0,0.5,30,5,0,2,1,1,0 -resize 50%,50%,100%,100%,5 -output '{0,b}'_sharpened.tiff,uchar,none,1

# Copy exif data from original image to resized base image
	exiftool -overwrite_original -TagsFromFile "$file" $(basename "$file" .tif)_sharpened.tiff

done

# Set the field separator back to default
IFS=$SAVEIFS
1 Like