Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Trying to create a sepia image...

  1. #11
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    No, I don't know who created that script but, what I do know is that you pass the image path e.g. :

    $cm = new bw('/path/to/your/image.png');

  2. #12
    Join Date
    Sep 2006
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ok, im lost,

    so something like this?

    PHP Code:
    <?php
    //Get the image
    $image $_GET['image'];

    $cm = new bw($image);

    // Get the dimensions
    list($width$height) = getimagesize($cm); 

    // This class turns a color image into Sepia

    class bw {
      
      var 
    $_bw;
      var 
    $_type;

      function 
    printImage() {
        switch (
    $this->_type) {
            case 
    IMAGETYPE_GIF : {
          
    header('Content-Type: image/gif');
          
    imagegif($this->_bw);
        } break;
        case 
    IMAGETYPE_JPEG : {
          
    header('Content-Type: image/jpeg');
          
    imagejpeg($this->_bw);
        } break;
        case 
    IMAGETYPE_PNG : {
          
    header('Content-Type: image/png');
          
    imagepng($this->_bw);
        } break;
        default : {
          
    header('Content-Type: image/jpeg');
          
    imagejpeg($this->_bw);
        } break;
        } 
    // switch
        
    imagedestroy($this->_bw);
      }
      
      function 
    bw($path) {
        
    // Let's find out what type is this image:
        
    if (@is_file($path)) {
          
    $this->_type = @exif_imagetype($path);
          switch (
    $this->_type) {
            case 
    IMAGETYPE_GIF : {
          
    $img = @imagecreatefromgif($path);
        } break;
        case 
    IMAGETYPE_JPEG : {
          
    $img = @imagecreatefromjpeg($path);
        } break;
        case 
    IMAGETYPE_PNG : {
          
    $img = @imagecreatefrompng($path);
        } break;
        default : {
          
    $img =_errorImg();
        } break;
          } 
    // switch ($this->_type)
          
          // If image was created successfully, do some magic stuff
          
    if ($img) {
        
    $this->_bw $this->_toBW($img);
        
    imagedestroy($img);
          } 
    // if ($this->_img)
        
    // if (@is_file...)
        
    else {
          
    $this->_bw $this->_errorImg();
        }
      }
      function 
    _errorImg() {
        return 
    imagecreate($width$height);
      }
      
      function 
    _toBW($src){
        
    $x imagesx($src);
        
    $y imagesy($src);

        
    $dest imagecreatetruecolor($x$y);

        for (
    $i=0;$i<$x;$i++) {
          for (
    $j=0;$j<$y;$j++) {
            
    $oldcolor imagecolorsforindex($srcimagecolorat($src$i$j));
        
    $newcolor = (int)(($oldcolor['red'] + $oldcolor['green'] + $oldcolor['blue']) / 3);
        
    $sepia = array(
                
    "red" => 145,
                
    "green" => 65,
                
    "blue" => 10
                 
    );
        
    $mix = array(
                    
    "o" => 0.7,
                
    "d" => 0.3
                 
    );
            
    $newr = ($newcolor*$mix['o'] + $sepia['red']*$mix['d'])>255?255:($newcolor*$mix['o'] + $sepia['red']*$mix['d']);
            
    $newg = ($newcolor*$mix['o'] + $sepia['green']*$mix['d'])>255?255:($newcolor*$mix['o'] + $sepia['green']*$mix['d']);
            
    $newb = ($newcolor*$mix['o'] + $sepia['blue']*$mix['d'])>255?255:($newcolor*$mix['o'] + $sepia['blue']*$mix['d']);
        
    imagesetpixel($dest$i$jimagecolorallocate($dest$newr$newg$newb ));
          } 
    // for($j
        
    // for ($i
        
        
    return $dest;
      }
    }

    import_request_variables('g','bw_');

    $bw = new bw($bw_im);
    $bw->printImage();

    ?>

  3. #13
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Take a look at the filter I mentioned, IMG_FILTER_COLORIZE. That would probably be easier.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  4. #14
    Join Date
    Aug 2005
    Posts
    971
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    True, why don't you try using image filters since they are easier than hard coding everything? However if it doesn't work out for you, you can always go back to that code and if anything goes wrong, we'll be here for you.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •