Re: How to generate an broun & white JPG with GD

From: Date: Sun, 03 Mar 2002 08:38:22 +0000
Subject: Re: How to generate an broun & white JPG with GD
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-86963@lists.php.net to get a copy of this message
Hi Here is a small php script to create sepia images from a jpeg, put it in the same place as your images and call it sepia.php. Uselike this: img src="/images/sepia.php/filename.jpg" <?
        $filename = ereg_replace("/","",$PATH_INFO);
        if($filename != ""):
                $im =imagecreatefromjpeg($filename);
                //convert to a pallette
                imagetruecolortopalette($im,1,256);
                $start_red = 2.1;                       //red scale at black
                $start_blue = 2.3;                      //blue scale at black
                $red_scale = ($start_red - 0.9)/256;    //blue modifier as greyscale goes to white
                $blue_scale = ($start_blue - 0.9)/256;  //ditto for red
                //loop through pallette
                for($x = 0;$x < 256;$x++){
                        $a = array();
                        $a = imagecolorsforindex ($im, $x);
                        //calc a grayscale value
                        $gs = intval(($a["red"]*0.3) + ($a["green"]*.59) + ($a["blue"]*.11));
                        $rm = $gs * $red_scale; //calc red modifier
                        $bm = $gs * $blue_scale; //calc blue modifier
                        $red_m = $start_red - $rm;
                        $blue_m = $start_blue - $bm;
                        $r = intval($gs * $red_m);              //scale red up
                        $g = $gs;                               //green no change
                        $b = intval($gs/$blue_m);               //scale blue down
                        imagecolorset ($im, $x, $r, $g, $b);
                }
                Header("Content-type: image/jpeg");
                ImageJpeg($im,'',30);
        endif;
?> Probably will only work with php-4+ and gd 2+ Tom At 02:42 AM 3/3/02, Andy wrote:
Hi there, I was recently browsing throught phpbuilder and did see the user pictures there. They are not black/white, but kind of brown white which look pretty cool and might save some disk space compared to true color. Here is the link: http://phpbuilder.com/columns/ying20000602.php3?page=1 Does anybody know how to do this with GD? Thanx for any help Andy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


« previous php.general (#86963) next »