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

From: Date: Mon, 04 Mar 2002 05:30:02 +0000
Subject: Re: How to generate an broun & white JPG with GD
Groups: php.general 
Request: Send a blank email to php-general+get-87038@lists.php.net to get a copy of this message
Hi Here is a better 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 != ""):
                $start_red = 2;                         //red scale at black
                $start_blue = 2.3;                      //blue scale at black
                $red_scale = ($start_red-1)/256;                //red modifier as greyscale goes to white
                $blue_scale = ($start_blue - 1)/256;    //ditto for blue
                //build a sepia lookup table
                $sepia = array();
                for($x = 0;$x < 256;$x++){
                        $red = intval($x * ($start_red - ($x * $red_scale)));
                        if($red > 255) $red = 255;
                        $blue = intval($x / ($start_blue - ($x * $blue_scale)));
                        $sepia[$x][0] = $red;
                        $sepia[$x][1] = $blue;
                }
                $im =imagecreatefromjpeg($filename);
                for($y = 0;$y < imagesy($im);$y++){
                        for($x = 0;$x < imagesx($im);$x++){
                                $pixel = imagecolorat($im, $x, $y);
                                $red = ($pixel & 0xFF0000) >> 16;
                                $green = ($pixel & 0x00FF00) >> 8;
                                $blue = $pixel & 0x0000FF;
                                $alpha = $pixel & 0x7F000000;
                                //get a greyscale value
                                $gs = intval(($red * 0.3) + ($green * 0.59) + ($blue * 0.11));
                                $p = $alpha | $sepia[$gs][1] | ($gs << 8) | ($sepia[$gs][0] << 16);
                                imagesetpixel ($im, $x, $y, $p);
                        }
                }
                Header("Content-type: image/jpeg");
                ImageJpeg($im,'',50);
        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 (#87038) next »