Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 411249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:58:06+00:00 2026-05-12T17:58:06+00:00

I hope someone can help, I have made a script that masks images… however

  • 0

I hope someone can help,

I have made a script that masks images… however it is reliant on a colour to mask with ( ‘green screen’ style). The trouble is if the image that I am masking contains that colour it is ruined.

What I am looking to do is prior to masking the image replace any occurance of my keying colour (0,0,255) with a similar colour such as 0,0,254.

I have found a few solutions based around gif’s or 256 colour PNG as they are indexed..

So my question is also will it be more efficient to convert it to a gif or 256 png then look through the index and replace the colour or search through every pixel and replace the colours.

Thanks,

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:58:06+00:00Added an answer on May 12, 2026 at 5:58 pm

    You need to open the input file and scan each pixel to check for your chromokey value.

    Something like this:

    // Open input and output image
    $src = imagecreatefromJPEG('input.jpg') or die('Problem with source');
    $out = ImageCreateTrueColor(imagesx($src),imagesy($src)) or die('Problem In Creating image');
    
    // scan image pixels
    for ($x = 0; $x < imagesx($src); $x++) {
        for ($y = 0; $y < imagesy($src); $y++) {
            $src_pix = imagecolorat($src,$x,$y);
            $src_pix_array = rgb_to_array($src_pix);
    
                // check for chromakey color
                if ($src_pix_array[0] == 0 && $src_pix_array[1] == 0 && $src_pix_array[2] == 255) {
                    $src_pix_array[2] = 254;
                }
    
    
            imagesetpixel($out, $x, $y, imagecolorallocate($out, $src_pix_array[0], $src_pix_array[1], $src_pix_array[2]));
        }
    }
    
    
    // write $out to disc
    
    imagejpeg($out, 'output.jpg',100) or die('Problem saving output image');
    imagedestroy($out);
    
    // split rgb to components
    function rgb_to_array($rgb) {
        $a[0] = ($rgb >> 16) & 0xFF;
        $a[1] = ($rgb >> 8) & 0xFF;
        $a[2] = $rgb & 0xFF;
    
        return $a;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hope someone can help. I have a simple scenario where clicking checkboxes is driving
I hope someone can help me since I have no clue whats going on
I hope someone can help... This issue has been discussed here and I have
I have a problem with CodeIgniter .htaccess file and hope that somebody can help
Hope someone can help. I have the code below which when the user hovers
Hello I have a problem with UIScrollView and I hope someone can help me.
Hope someone can help me I have declared the variable <?php $sitename = http://
I hope someone can help me with this Javascript. I have an Object called
I hope someone can help me with my MySQL problem. I have a bug
I really hope someone can help me with this. Basically i have an issue

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.