SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot ozonew4m's Avatar
    Join Date
    Apr 2006
    Location
    at my desk
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    convert to black and white(not grayscale) with gd library

    im loading an image using

    $img = imagecreatefromjpeg('image.jpg');

    what i want to do is convert all light pixels to white and all dark pixels to black and then output the image to the page...

    can somebody pleeeease guide me on how to do this... ive found hundreds of tutorials of how to greyscale an image but i just want black and white...

    pleeeeeeease

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Well, this should do what you want:
    PHP Code:
    header("content-type: image/jpeg");
    $img imagecreatefromjpeg('img.jpg');
    imagefilter($imgIMG_FILTER_GRAYSCALE); //first, convert to grayscale
    imagefilter($imgIMG_FILTER_CONTRAST, -255); //then, apply a full contrast
    imagejpeg($img); 
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Zealot ozonew4m's Avatar
    Join Date
    Apr 2006
    Location
    at my desk
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    perfect.. thank you very much i appreciate it


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
  •