Skip to content

Instantly share code, notes, and snippets.

@TheRolfFR
Created December 30, 2022 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheRolfFR/9f23b6b928cca70296bee995f24eefe1 to your computer and use it in GitHub Desktop.
Save TheRolfFR/9f23b6b928cca70296bee995f24eefe1 to your computer and use it in GitHub Desktop.
Modify Apache2::Imager::Resize to fix iCCP: known incorrect sRGB profile error

Modify Apache2::Imager::Resize to fix iCCP: known incorrect sRGB profile error

First this error is not your module or your library in fault, it's the libpng library fault.

Since libpng 1.6 release, the library became more aggresive about incorrect iCCP data chunks. To fix that problem, you could go to a prior version or modify the images so that the iCCP chunk is removed.


Install ImageMagick with your packet manager:

sudo apt install imagemagick

Then what you need to do is modify your code so that on the first encounter of the error, you strip the file accordingly. On the script bellow it's perl, but you could easily adapt it to your programming language to make a system call.

Back to my case, go inside the Resize module perl file location (me it was /usr/local/share/perl/5.30.0/Apache2/Imager/Resize.pm) and edit the line written in the error log (me it was /var/log/apache2/error.log), mine was line 313. And modify the file accordingly to insert the new lines before said error line:

    if (not $im->open( file => $filename ) and index($im->errstr, "incorrect sRGB profile") != -1) {
        # call ImageMagick convert to strip iCCP chunk
        my @args = ("convert", $filename, "-strip", $filename);
        system(@args) == 0 or return fail("Failed to strip iCCP profile on $filename: $?");
    }
    $im->open( file => $filename ) or return fail("Cannot read $filename: " . $im->errstr);
    $im = resize($im, \%img_args);

On first encounter, it calls convert function from ImageMagick, which strips the iCCP incorrect sRGB profile chunk. You can then open it normally after and no error should appear.


Hope it helped you with your problems!

-TheRolf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment