Stripping sRGB profile from PNGs in python

Emile van Sebille emile at fenx.com
Thu Jul 23 13:42:01 EDT 2015


On 7/23/2015 10:31 AM, Ryan Holmes wrote:
> We're getting this error when trying to load some of out projects images:
>
>      libpng warning: iCCP: known incorrect sRGB profile
>
> The source files that we have some with incorrect sRGB profiles. We don't have control over the source files, but what we normally do is take them and scale them down for our own project. To fix this issue, we can use this shell one-liner:
>
>      find . -type f -name "*.png" -exec convert {} {} \;
>
> Which basically converts the ONGs into themselves, but it strips the profile (or maybe overwrites with a correct profile).
>
> We would like to incorporate this functionality into our python script which scales the source images, but we haven' found a way to do this. Any thoughts?


Use the appropriate shell out command for your python version.  There've 
been too many over the years -- on the system I'm at today running 
Python 2.5 I'm using the commands module.

For example:

commands.getoutput('for ii in /proc/[0-9]*/environ; do echo $ii; strings 
$ii ; done').split()

Emile






More information about the Python-list mailing list