Login   Register  
PHP Classes
elePHPant
Icontem

File: greyimg.php3

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of stef  >  B&W Image  >  greyimg.php3  >  Download  
File: greyimg.php3
Role: ???
Content type: text/plain
Description: Grey Image
Class: B&W Image
Author: By
Last change:
Date: 13 years ago
Size: 1,090 bytes
 

Contents

Class file image Download
<?
#this file outputs a grey version of specified image
#use of this file:
#    in the image tag, <img border=0 src=greyimage.php3?src=imagesrc&col=colno >
# where imagesrc is the source of the original colour version
# where colno is 0 for grey, 1 for red, 2 green, 3 blue

function MakeColoursGrey($im,$col){
  $total=ImageColorsTotal($im);
  for($i=0;$i<$total;$i++){
     $old=ImageColorsForIndex($im,$i);
     
     #trying to keep proper saturation when converting
     $commongrey=(int)($old[red]+$old[green]+$old[blue])/3;
     if(!$col){
       ImageColorSet($im,$i,$commongrey,$commongrey,$commongrey);
     }elseif($col==1){
       ImageColorSet($im,$i,$commongrey,0,0);
     }elseif($col==2){
       ImageColorSet($im,$i,0,$commongrey,0);
     }elseif($col==3){
       ImageColorSet($im,$i,0,0,$commongrey);
     }
  }
}

$img=imagecreatefromgif($src);

#change the colours to grey
MakeColoursGrey($img,$col);

#send the http header, this outputs an image of type gif
Header("Content-Type: image/gif");

#send the image
ImageGif($img);


?>