This gist describes how to use the ImageMagick and OpenSSL command line tools to encrypt an image using ECB mode.
First we need to gather some information about the original image. This will tell us what size to use in our final step.
$ identify Braintree.png
Braintree.png PNG 898x229 898x229+0+0 8-bit sRGB 65KB 0.000u 0:00.000
Looks like the image is 898x229.
Next we need to convert the image into the RGBA format. This is a simple binary format that only contains uncompressed pixel data and no meta information, like image dimensions.
$ convert -depth 32 Braintree.png Braintree.rgba
Next we will use the OpenSSL command line utility to encrypt the RGBA file.
$ openssl enc -aes-128-ecb -e -in Braintree.rgba -out Braintree-ecb.rgba -k toomanysecrets
This will encrypt the file for us using a key derived from the given passphrase. After we have our encrypted file it is time to turn it back into an image.
$ convert -size 898x229 -depth 32 Braintree-ecb.rgba Braintree-ecb.png
We use the size we gathered in the first step to reconstruct an image of the proper dimensions. Now we have an image that has been encrypted under ECB mode. The steps are easy to repeat with CBC or any other supported cipher mode.