|
| 1 | + |
1 | 2 | <?php
|
2 | 3 | /**
|
3 | 4 | * Image processing functions
|
@@ -74,6 +75,10 @@ function upload_file($ref,$no_exif=false,$revert=false,$autorotate=false)
|
74 | 75 | $old_path=get_resource_path($ref,true,"",true,$old_extension);
|
75 | 76 | if (file_exists($old_path)) {unlink($old_path);}
|
76 | 77 | }
|
| 78 | + |
| 79 | + // also remove any existing extracted icc profiles |
| 80 | + $icc_path=get_resource_path($ref,true,"",true,'icc'); |
| 81 | + if (file_exists($icc_path)) {unlink($icc_path);} |
77 | 82 | }
|
78 | 83 |
|
79 | 84 | if (!$revert){
|
@@ -110,7 +115,14 @@ function upload_file($ref,$no_exif=false,$revert=false,$autorotate=false)
|
110 | 115 | }
|
111 | 116 |
|
112 | 117 | chmod($filepath,0777);
|
113 |
| - $status="Your file has been uploaded."; |
| 118 | + |
| 119 | + global $icc_extraction; |
| 120 | + if ($icc_extraction){ |
| 121 | + extract_icc_profile($filepath); |
| 122 | + } |
| 123 | + |
| 124 | + |
| 125 | + $status="Your file has been uploaded."; |
114 | 126 | }
|
115 | 127 | }
|
116 | 128 | }
|
@@ -759,13 +771,36 @@ function create_previews_using_im($ref,$thumbonly=false,$extension="jpg",$previe
|
759 | 771 | $wpath=get_resource_path($ref,true,$ps[$n]["id"],false,"jpg",-1,1,true,"",$alternative);
|
760 | 772 | if (file_exists($wpath)){unlink($wpath);}
|
761 | 773 |
|
762 |
| - # Preserve colour profiles? (omit for smaller sizes) |
763 |
| - $profile="+profile \"*\" -colorspace RGB"; # By default, strip the colour profiles ('+' is remove the profile, confusingly) |
764 |
| - if ($imagemagick_preserve_profiles && $id!="thm" && $id!="col" && $id!="pre" && $id!="scr") {$profile="";} |
| 774 | + |
| 775 | + # EXPERIMENTAL CODE TO USE EXISTING ICC PROFILE IF PRESENT |
| 776 | + global $icc_extraction, $icc_preview_profile, $icc_preview_options; |
| 777 | + if ($icc_extraction){ |
| 778 | + $iccpath = get_resource_path($ref,true,'',false,'icc'); |
| 779 | + if (!file_exists($iccpath) && !isset($iccfound)) { |
| 780 | + // extracted profile doesn't exist. Try extracting. |
| 781 | + if (extract_icc_profile($file)){ |
| 782 | + $iccfound = true; |
| 783 | + } else { |
| 784 | + $iccfound = false; |
| 785 | + } |
| 786 | + } |
| 787 | + } |
| 788 | + |
| 789 | + if($icc_extraction && file_exists($iccpath)){ |
| 790 | + // we have an extracted ICC profile, so use it as source |
| 791 | + $targetprofile = dirname(__FILE__) . '/../iccprofiles/' . $icc_preview_profile; |
| 792 | + $profile = " +profile \"*\" -profile $iccpath $icc_preview_options -profile $targetprofile "; |
| 793 | + } else { |
| 794 | + // use existing strategy for color profiles |
| 795 | + # Preserve colour profiles? (omit for smaller sizes) |
| 796 | + $profile="+profile \"*\" -colorspace RGB"; # By default, strip the colour profiles ('+' is remove the profile, confusingly) |
| 797 | + if ($imagemagick_preserve_profiles && $id!="thm" && $id!="col" && $id!="pre" && $id!="scr") {$profile="";} |
| 798 | + } |
| 799 | + |
765 | 800 |
|
766 | 801 | $runcommand = $command ." +matte $profile -resize " . $tw . "x" . $th . "\">\" ".escapeshellarg($path);
|
767 | 802 | $output=shell_exec($runcommand);
|
768 |
| - # echo $runcommand."<br>"; |
| 803 | + # echo $runcommand."<br>\n"; |
769 | 804 | # Add a watermarked image too?
|
770 | 805 | global $watermark;
|
771 | 806 | if ($alternative==-1 && isset($watermark) && ($ps[$n]["internal"]==1 || $ps[$n]["allow_preview"]==1))
|
@@ -1415,4 +1450,41 @@ function AutoRotateImage ($src_image){
|
1415 | 1450 | }
|
1416 | 1451 |
|
1417 | 1452 |
|
| 1453 | +function extract_icc_profile($infile) { |
| 1454 | + global $config_windows, $imagemagick_path; |
| 1455 | + |
| 1456 | + # Locate imagemagick, or fail this if it isn't installed |
| 1457 | + $command=$imagemagick_path . "/bin/convert"; |
| 1458 | + if (!file_exists($command)) {$command=$imagemagick_path . "/convert";} |
| 1459 | + if (!file_exists($command)) {$command=$imagemagick_path . "\convert.exe";} |
| 1460 | + if (!file_exists($command)) {return false;} |
| 1461 | + |
| 1462 | + if ($config_windows){ $stderrclause = ''; } else { $stderrclause = '2>&1'; } |
| 1463 | + |
| 1464 | + // outfile will be same name as infile, except with icc ext |
| 1465 | + $ext = strrchr($infile,'.'); |
| 1466 | + if ($ext !== false){ |
| 1467 | + $outfile = substr($infile,0,-strlen($ext)) . '.icc'; |
| 1468 | + } else { |
| 1469 | + $outfile = $infile . '.icc'; |
| 1470 | + } |
| 1471 | + |
| 1472 | + if (file_exists($outfile)){ |
| 1473 | + // extracted profile already existed. We'll remove it and start over |
| 1474 | + unlink($outfile); |
| 1475 | + } |
| 1476 | + |
| 1477 | + $cmdout= shell_exec("$command $infile $outfile $stderrclause "); |
| 1478 | + |
| 1479 | + if ( preg_match("/no color profile is available/",$cmdout) || !file_exists($outfile) ||filesize($outfile) == 0){ |
| 1480 | + // the icc profile extraction failed. So delete file. |
| 1481 | + if (file_exists($outfile)){ unlink ($outfile); }; |
| 1482 | + return false; |
| 1483 | + } |
| 1484 | + |
| 1485 | + if (file_exists($outfile)) { return true; } else { return false; } |
| 1486 | + |
| 1487 | +} |
| 1488 | + |
| 1489 | + |
1418 | 1490 | ?>
|
0 commit comments