SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile PHP GD -> get color -> print color

    Hello everyone!

    I need a little help to get functions names from the GD library.
    first i want to say i have a little knowledge with GD library like create image with words and etc.

    So , what i'm trying to do is to take image and than
    take the color of the first pixel on the top left than do some function work and than
    set this pixel on the top left to another color.

    now , i know how the algorithm should look like , i just don't know what function i need to use to:
    take specific pixel color from the image
    set new color for pixel on specific place

    i'll be glad if you could help me with that ,
    regards , Mor.

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    Getting function names from a library is as simple as looking at the manual page for GD. Specifically, you're looking for imagecreatefrom<type>, imagecolorat, and imagesetpixel

  3. #3
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,067
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    I think you'll need the imagecolorat() function to get the colour of the pixel.

    The imagesetpixel() function is probably what your looking for to set a pixel to a certain colour.
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  4. #4
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow thank you guys , it really really helped !
    but i need to work with hex not with rgb , how can it work out?

  5. #5
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    hex = "#".dechex(Red).dechex(Green).dechex(Blue);

  6. #6
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow , this is my favorite community! thanks.

  7. #7
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hey i got two more questions :
    how can i save image that i made with gd?
    and how can i open image that exist in the upload folder and put it into variable so i can take the size of the image and some other things..?
    thanks , Mor.

  8. #8
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    imagecreatefrom<type> will put an image into a variable.
    As far as saving them, write the result of your image generation function (imagepng, imagejpeg etc) into a file, with something like file_put_contents.

  9. #9
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you

  10. #10
    SitePoint Member
    Join Date
    Sep 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i though i had problem , but it solve , sorry.

  11. #11
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    73 Post(s)
    Tagged
    0 Thread(s)
    imagesetpixel's color parameter is not a hex string, but a color object, as created by imagecolorallocate.


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
  •