Search code examples
pythonpython-3.xsteganographystepic

Python3 Steganography / stepic / ValueError: Unsupported pixel format: image must be RGB, RGBA, or CMYK


I'm fairly new to python, and I'm trying out Steganography. I'm using the libraries Stepic and Image to try to encrypt user input messages onto any image. My script will do just fine until the very last step, the encryption onto the image. My error is, "ValueError: Unsupported pixel format: image must be RGB, RGBA, or CMYK" I can't think of anything to try so I've come here. Here is my code:

from PIL import Image
import stepic

i = input("Name of File (With extension): ")
img = Image.open(i)

message = input("Message: ")

message = message.encode()

encoded_img = stepic.encode(img, message)

encoded_img.save(input("Name of encypted image: "))
print("Completed!")

Solution

  • Try converting the image to any supported format before you pass it to stepic.encode(). An example code would be:

    from PIL import Image
    import stepic
    
    i = input("Name of File (With extension): ")
    img = Image.open(i)
    
    message = input("Message: ")
    
    message = message.encode()
    
    imgConv = img.convert("RGB") # Here
    encoded_img = stepic.encode(imgConv, message)
    
    encoded_img.save(input("Name of encypted image: "))
    print("Completed!")