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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Apr 2008
    Posts
    685
    Thanks
    15
    Thanked 105 Times in 104 Posts

    Is It Possible to Remove Background From Images?

    Hi, Is it possible to remove the background of my image and make it transparent using PHP?

    For example my image is a .jpg with a white background, I need the white gone.

    We need to be able to distinguish the background from the actual image itself, I know PHP is capable of great things, but is it capable of this?

    If removing the white and making it transparent isn't possible, can we change the background colour from white to say black?

    Again the problem is more distinguishing the background from the image itself I guess..

  • #2
    Regular Coder
    Join Date
    Jul 2009
    Posts
    187
    Thanks
    16
    Thanked 8 Times in 8 Posts
    I don't think it would be possible with a jpg? But i'm not sure about that.

    I know you can create png images with transparent backgrounds
    And I know PHP can create images with transparent backgrounds,
    I'm just not sure about this, but it seems to me if it can do the above it should be able to do that

  • #3
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    not sure, not a GD man, there are a few members who are great with this kinda thing. Maybe worth going to php.net and checking out the GD manual.
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by Scriptet View Post
    Hi, Is it possible to remove the background of my image and make it transparent using PHP?

    For example my image is a .jpg with a white background, I need the white gone.

    We need to be able to distinguish the background from the actual image itself, I know PHP is capable of great things, but is it capable of this?

    If removing the white and making it transparent isn't possible, can we change the background colour from white to say black?

    Again the problem is more distinguishing the background from the image itself I guess..
    that don't depend of language, the main problem is to decide when something is a background things and when not,
    if you base the decison of frecvency of each color some time will work sometimes not and I'm sure the results will have low quality.
    The problem with removing a color, white as you said, and make it transparent is easy and can be done but don't work for any image format.

    best regards

  • #5
    Regular Coder
    Join Date
    Apr 2008
    Posts
    685
    Thanks
    15
    Thanked 105 Times in 104 Posts
    Hm I did get round to testing this but things were poor quality, and I found no way of distinguishing white in the background from white in the actual image.

    The only logic I can think of to make this work, is if it works from the outer edge of the image, changes the white pixels into transparent pixels, and then the first time it spots a different colour, stop.

    But I don't think there's any way it's going to be done with reasonable quality.

    Anyway not to worry!


  •  

    Posting Permissions

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