communication
 databases
 directories
 file handling
 html and code
 image editing
 image listing
 sessions and co
 string handling
 information
 forms
 apple stuff
 image handling
 array handling
 lixlpixel
php - snippets
google search terms detected and highlighted.
remove highlighting | keep highlighting
make snippet in "image editing" - download "grayscale an image"
 search
php - snippets

Valid CSS!

php webring logo
prev next
random list
join the Ring!

image editing - grayscale an image was created/last modified on Sat 13 Mar 2004 2:45 PM

converts an image into greyscale
    
     <?php
     
   
function create_grey($input,$output)
   {
    
$bild = imagecreatefromjpeg($input);
    
$x = imagesx($bild);
    
$y = imagesy($bild);
   
    for(
$i=0; $i<$y; $i++)
    {
     for(
$j=0; $j<$x; $j++)
     {
      
$pos = imagecolorat($bild, $j, $i);
      
$f = imagecolorsforindex($bild, $pos);
      
$gst = $f["red"]*0.15 + $f["green"]*0.5 + $f["blue"]*0.35;
      
$col = imagecolorresolve($bild, $gst, $gst, $gst);
      
imagesetpixel($bild, $j, $i, $col);
     }
    }
    
imagejpeg($bild,$output,90);
   }
     
     
?>            

learn more about some of the PHP functions used in this snippet: for, function, imagecolorat, imagecolorresolve, imagecolorsforindex, imagecreate, imagecreatefromjpeg, imagejpeg, imagesetpixel, imagesx, imagesy

view the GNU general license - view the GNU library license - search on PHPsnippets - see your code like this

 a lixlpixel.com site

PHParadise.com - PHP-classes.org - your site on safari