Graham
Graham

Reputation: 17

XMP Image presets and conversions

I handle a lot of my photos in bulk on a regular basis. I'm looking to apply a common XMP preset (developed in camera raw for cr2 files)

Originally I looked at using ap ython module to apply the preset, then convert the image from cr2 to jpeg with rawpy. This didn't work and a lot of the research I did pointed to the fact that these modules couldn't handle the xmp application within the module, due to complex lens corrections etc.

What I then thought was to look at the process manually, and it looked as though that when I applied these XMPs to the cr2 files, all that was happenign was that XMP file was being copied and renamed to suit the filename of the corresponding cr2(RAW) file.

So I thought why not write a code that copies that across for every file, then do the raw conversion once the XMP file was matched with the raw.

The previews after I run this code on the raw files work perfectly in bridge, so I can see that they're being copied and applied correctly to the cr2 file.

My question is, is there a way to have the cr2 file handled with these alterations on hand?

I wrote a sleep into the code to give it time to have the presets applied, per below

import os
import shutil
import PIL
import rawpy
import imageio
from PIL import Image
import time


xmp_preset = "path/to/PRESET.xmp"
raw_sorted = "path/to/RAW/"
jpg_output = "path/to/JPEG/"

for f in sorted(os.listdir(raw_sorted)):
    f_name,f_ext = (os.path.splitext(f))
    xmp_name01 = ('{}{}'.format(f_name,".xmp"))


    if os.path.exists(".DS_Store"):
        os.remove(".DS_Store")
    if os.path.exists("Thumbs.db"):
        os.remove("Thumbs.db")

    if f.endswith(".cr2"):
        shutil.copy(xmp_preset, raw_sorted)
        os.rename(raw_sorted + "PRESET.xmp", raw_sorted + xmp_name01)



time.sleep(10)

for f in os.listdir(raw_sorted):
    if f.endswith(".cr2"):
        f_name, f_ext = os.path.splitext(f)
        filepath = os.path.join(raw_sorted,f)
        jpegext = ".jpg"
        with rawpy.imread(filepath) as raw:
            rgb = raw.postprocess(use_camera_wb=True,gamma=None)
            path = os.path.join(jpg_output,f_name)
            newname = ("{}{}".format(path,jpegext))

            imageio.imwrite(newname,rgb)

The code works fine, it brings the XMP file across, renames it correctly and I can see that it has been applied, however, when the jpeg is output to the defined folder, it's done so as if the XMP was never a factor.

Is there a way to output the jpeg file using the applied XMP? I tried using rawpy parameters to try to get as close as possible to the desired look but it's just not right.

Upvotes: 0

Views: 446

Answers (0)

Related Questions