Created
April 2, 2018 07:00
-
-
Save ikarius6/d4b5c17143b5a16dde1ab97271bd61fc to your computer and use it in GitHub Desktop.
Replacing display metadata in bulk for ICC files, from mntrRGB to scnrRGB, requires folders files and final - Mr.Jack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Replacing display metadata in bulk for ICC files, from mntrRGB to scnrRGB - Mr.Jack | |
*/ | |
$read_folder = "./files/"; | |
$write_folder = "./final/"; | |
$scanned_directory = array_diff(scandir($read_folder), array('..', '.')); | |
foreach($scanned_directory as $file){ | |
echo "<p>Converting ".$file." - "; | |
if(!$fp = fopen ($read_folder . $file, 'rb')) return 0; | |
if(!$header = fread ($fp, 20)) return 0; //20 bytes header | |
$hex_header = unpack ("@12/H16display", $header); | |
if($hex_header['display'] === "6d6e747252474220"){ //mntrRGB | |
$new_display_mode = "73636e7252474220"; //scnrRGB | |
$bin = pack("H*", $new_display_mode); //Hex to Bin | |
copy($read_folder . $file, $write_folder . $file); | |
if(!$fw = fopen ($write_folder . $file, 'c')) return 0; | |
fseek($fw, 12); //skip the first 12 bytes | |
fwrite($fw, $bin); | |
fclose($fw); | |
echo "<strong style='color:green'>Success</strong></p>" . PHP_EOL; | |
}else{ | |
echo "<strong style='color:orange'>Not Match</strong></p>" . PHP_EOL; | |
} | |
fclose($fp); | |
} | |
echo "<strong>Done</strong>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment