note 130495 added to imagick.profileimage

From: Date: Sat, 27 Sep 2025 02:52:36 +0000
Subject: note 130495 added to imagick.profileimage
Groups: php.notes 
Request: Send a blank email to php-notes+get-222359@lists.php.net to get a copy of this message
Instantiating an image files, and attempting to save them in PNG format using setImageFormat('PNG'), I occasionally encountered "gd-png: libpng warning: iCCP: profile 'icc': 'CMYK': invalid ICC profile color space". However, transformimagecolorspace( \Imagick::COLORSPACE_SRGB ) had not effect, because getImageColorspace() did not indicate COLORSPACE_CMYK. Instead, one has to check for the presence of any ICC profile, inspect the ICC profile header (offset 16) for the "CMYK" color space tag, and then remove the ICC profile: $ICC_count = remove_ICC( $image, 'CMYK'); function remove_ICC( \Imagick $image, ?string $colorspace ): int { $icc_count = 0; foreach ( $image->getImageProfiles( 'icc' ) as $name => $profile ) { if ( empty( $colorspace ) or 0 === strcasecmp( $colorspace, substr( $profile, 16, 4 ) ) ) // Either consider all ICC profiles, or just those matching the color space. $icc_count++; } if ( $icc_count > 0 ) $image->profileImage( 'icc', null ); // Delete any ICC profiles. return $icc_count; } ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.5.137 (proxied: 2600:4040:a518:5200:9565:b1b8:f182:10e9) ---- Manual Page -- https://php.net/manual/en/imagick.profileimage.php Edit -- https://main.php.net/note/edit/130495 Del: integrated -- https://main.php.net/note/delete/130495/integrated Del: useless -- https://main.php.net/note/delete/130495/useless Del: bad code -- https://main.php.net/note/delete/130495/bad+code Del: spam -- https://main.php.net/note/delete/130495/spam Del: non-english -- https://main.php.net/note/delete/130495/non-english Del: in docs -- https://main.php.net/note/delete/130495/in+docs Del: other reasons-- https://main.php.net/note/delete/130495 Reject -- https://main.php.net/note/reject/130495 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#222359) next »