How to create image upload hooks that generate thumbnails where ICC color profiles embedded?

maxm / 2016-02-15 22:30:38   

As PHP GD library doesn't copy the ICC color profiles, I do wish to insert a function after thumbnail files are generated to post-process them and copy the ICC profile from the source image.

  1. I think that inserting the thumbnail post-process hooks needs to be done in /lib/media.php, once for sys- files and once for th- files. That is function sys_thumb() and function upload_image().
  1. The idea is to insert this post-processing after line:
  2. $this->do_output($output_image, $this->image);
  3. and before line:
  4. imagedestroy($output_image);.
  1. I do need the <strong>source image location</strong>, that is path and filename. My idea is to use $this->input_image for that. And I need the generated <strong>resized thumbnail location</strong>, for which I use $this->image.

After making these changes, image uploading fails silently.

  1. Questions:
  2. 1. How to detect jpeg images? if ($this->filemime == 'jpg')?
  3. 2. Are the suggested hook insertion locations ok?
  4. 3. Are the suggested source and destination file locations ok?
  5. 4. How to turn on debugging output (all error messages)?

maxm / 2016-02-16 21:45:22   

The image ICC manipulation library had some "throw new Exception" statements. After changing these to "echo" debugging became a lot easier. And right now the ICC color profiles remain embedded in the resized images and thumbnails.

maxm / 2016-02-16 22:02:09   

Sharing with the community, what have I changed in legacy version of indexhibit (0.73) to keep the ICC profiles embedded in the thumbnails and resized images?

  1. 1. I downloaded an image ICC manipulation library from sourceforge.net/projects/jpeg-icc/
  2. 2. I extracted the zip file and copied file class.jpeg_icc.php to /ndxz-studio/lib/
  3. 3. I modified file /ndxz-studio/lib/media.php
  1. I modified class.jpeg_icc.php by searching for every throw new Exception statement and replaced it with an echo. That will save you time to figure out in case anything is wrong.
  1. The /ndxz-studio/lib/media.php modifications are:
  2. 4. insert require_once('class.jpeg_icc.php'); before class Media.
  3. 5. in function function upload_image( just before imagedestroy($output_image); are inserted these lines:
  4.             // copy ICC profile
  5.             if (($this->filemime == 'jpg') || ($this->filemime == 'jpeg'))
  6.             {
  7.                 $icc = new JPEG_ICC();
  8.                 $icc->LoadFromJPEG($this->path . $this->filename);
  9.                 $icc->SaveToJPEG($this->image);
  10.             }
  11. 6. in function function sys_thumb( just before imagedestroy($output_image); are inserted these lines:
  12.         // copy ICC profile
  13.         if (($this->filemime == 'jpg') || ($this->filemime == 'jpeg'))
  14.         {
  15.             $icc = new JPEG_ICC();
  16.             $icc->LoadFromJPEG($this->path . $this->filename);
  17.             $icc->SaveToJPEG($image);
  18.         }

This thread has been closed, thank you.