Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Retrieve pixels from image

    Hi,

    Imagine I have a photo/image and I want to know what color is attributed to a certain pixel.
    Is it possible to do that with PHP?

    I found this in the PHP manual:

    <?php
    $im = ImageCreateFromPng("rockym.png");
    $rgb = ImageColorAt($im, 100, 100);
    $r = ($rgb >> 16) & 0xFF;
    $g = ($rgb >> 8) & 0xFF;
    $b = $rgb & 0xFF;
    ?>

    but apparently, it gives me three different colors. Plus, would it still work if $im points to an image file?

    Thanks.

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,169
    Thanks
    19
    Thanked 65 Times in 64 Posts
    ...it gives you the RGB color in $rgb and the r,g,b separated into $r, $g, $b variables
    $im does point to an image file...'rockym.png'


  •  

    Posting Permissions

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