Writing an image's ColorSync profile on a Mac

121 Views Asked by At

I'm making an lsb-steganography project and one issue is that the image's the program outputs are different in color to the original image when nothing is changed (rgb values are the same), and I found the reason to be because the new images being generated dont have an LCD profile as their color profile.

So far I have this code to access the image's 'ColorSync profile':

def get_image_color_sync_profile(image_path: str) -> str:
    result = os.popen(f'sips -g profile {image_path}').read()
    return result

which gives me the string /Users/xxxxxxxxxx/Desktop/xxxx.png profile: Color LCD (x's are personal info but have the same length)

However I'm struggling with changing the characters of the string (the ones that mention the color profile). If I have an image with another profile, I have the string s = /Users/xxxxxxxxxx/Desktop/xxxx.png profile: something_else and I want to change s[37:] to 'Color LCD' but I get various errors such an unknown error and Error: Profile at profile: Color LCD Color LCD cannot be opened Error: Invalid replacement profile Error 13: an unknown error occurred Try 'sips --help' for help using this tool

Any tips on how to edit the color profile of an image on Mac using python?

I've tried simply replacing the color profile text since it's a string however it does not allow that. I was expecting the color profile in the string to change.

1

There are 1 best solutions below

0
On

A colour profile is a chunk of data; it cannot be replaced by a textual operation.

It may be possible to copy the profile from the original image, by using sips -x foo.dat orig.png to extract the profile, and sips -e foo.dat new.png to embed it into the new image.