Here is the new code. Changes include :
displayimage.php :
1) Copied code to get file name of the image displayed. If the image is an intermediate image, a user-definable prefix (defaults to normal_ is added to the filename. The intermediate image is used for the histogram creation, because it returns results that are the same as the full sized image, and the histogram is created quicker with smaller file sizes.
2) Since a histogram is really only relevant for photos, and since Coppermine is a photo gallery software, and since JPG is used to get a good quality image, with low file size, I've added code to only do the histogram from a JPG
3) The entire code is wrapped in a simple GD detection. If GD is not installed, none of the code will be run.
Again, this is in the function html_picinfo() in displayimage.php
// Added 6/10/05 - Anton Sparrius
// Creation/Display of histogram
if (function_exists('ImageTypes')) { // Only do if GD exists
if($CONFIG['thumb_use']=='ht' && $CURRENT_PIC_DATA['pheight'] > $CONFIG['picture_width'] ){ // The wierd comparision is because only picture_width is $
$condition = true;
}elseif($CONFIG['thumb_use']=='wd' && $CURRENT_PIC_DATA['pwidth'] > $CONFIG['picture_width']){
$condition = true;
}elseif($CONFIG['thumb_use']=='any' && max($CURRENT_PIC_DATA['pwidth'], $CURRENT_PIC_DATA['pheight']) > $CONFIG['picture_width']){
$condition = true;
}else{
$condition = false;
}
if ($CONFIG['make_intermediate'] && $condition ) {
$picture_url = get_pic_url($CURRENT_PIC_DATA, 'normal');
} else {
$picture_url = get_pic_url($CURRENT_PIC_DATA, 'fullsize');
}
if (strtoupper(substr($picture_url,strlen($picture_url)-3,3))=="JPG") {
$info[$lang_picinfo['Histogram']]="<img src='histo.php?image=".$picture_url."'>";
}
}
// End Addition
return theme_html_picinfo($info);
}
In the Coppermine root folder, create a file called histo.php with the following code.
Changes include adjustments for the new file name (normal_ etc) and cosmetic changes to the actual histogram. A PNG is created in the same folder as the image. It looks like the PNG is normally around 2k.
<?php
// Histogram creation
// Created by Anton Sparrius (Spaz) 6/9/05 anton_spaz@yahoo.com
// Free to use and change, provided you keep these lines :)
//
$tmp_image = $_REQUEST['image'];
$image_array=split('[/\]',$tmp_image);
$image=$image_array[count($image_array)-1];
$path=rtrim($tmp_image,$image);
$hist_file="hist_".substr($image,0,strlen($image)-4).".png";
if (file_exists($path.$hist_file)) {
$im=imagecreatefromPNG($path . $hist_file);
imagePNG($im);
imagedestroy($im);
} else {
$im=imagecreatefromjpeg($path.$image);
for($i=0;$i<imagesx($im);$i+=2)
{
for($j=0;$j<imagesy($im);$j++)
{
$rrggbb=imagecolorsforindex ($im, imagecolorat($im,$i,$j));
$r[$rrggbb['red']]+=1;
$g[$rrggbb['green']]+=1;
$b[$rrggbb['blue']]+=1;
}
}
for ($i=0;$i<256;$i++)
{
$max[$i]=($r[$i]+$g[$i]+$b[$i])/3;
}
$max_value=max($max)/150;
$m[0]=max($r);
$m[1]=max($b);
$m[2]=max($g);
$max_rgb=max($m)/150;
$im_out = imageCreate (284, 164);
$background = imageColorAllocate($im_out,100,100,100);
$box_fill = imageColorAllocate($im_out,70,70,70);
$white=ImageColorAllocate($im_out,200,200,200);
$black=ImageColorAllocate($im_out,20,20,20);
$grey=ImageColorAllocate($im_out,160,160,160);
$red=ImageColorAllocate($im_out,255,0,0);
$green=ImageColorAllocate($im_out,0,200,0);
$blue=ImageColorAllocate($im_out,0,0,255);
$ry=107;
$gy=107;
$by=107;
imageFilledRectangle($im_out,13,6,270,158,$box_fill);
for($i=0;$i<256;$i++)
{
imageLine($im_out, $i+14, 157, $i+14, 157-($max[$i]/$max_value),$white);
imageLine($im_out, $i+13, $ry, $i+14, 157-($r[$i]/$max_rgb), $red);
imageLine($im_out, $i+13, $gy, $i+14, 157-($g[$i]/$max_rgb), $green);
imageLine($im_out, $i+13, $by, $i+14, 157-($b[$i]/$max_rgb), $blue);
$ry=157-($r[$i]/$max_rgb);
$gy=157-($g[$i]/$max_rgb);
$by=157-($b[$i]/$max_rgb);
}
imageSetThickness($im_out,3);
imageLine($im_out,13,158,272,158,$grey);
imageLine($im_out,13,6,272,6,$black);
imageLine($im_out,13,6,13,158,$black);
imageLine($im_out,272,6,272,158,$grey);
imagePNG($im_out,$path . $hist_file);
imageDestroy($im);
imagedestroy($im_out);
$im=imagecreatefromPNG($path . $hist_file);
imagePNG($im);
imagedestroy($im);
}
?>
Example of the histogram. Note, if you have the image information turned off, you will not see the histogram.
(https://forum.coppermine-gallery.net/proxy.php?request=http%3A%2F%2Fspaz.is-a-geek.com%2Fpics%2Falbums%2Fuserpics%2F10001%2Fhisto_example.jpg&hash=8a5c87ed71487055bf1d029482f412650d62a5c8)