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

  • Home
  • SEARCH
  • 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 8755841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:56:02+00:00 2026-06-13T13:56:02+00:00

For example: $im = imagecreatefrompng(php.png); $rgb = imagecolorat($im, 10, 15); $r = ($rgb >>

  • 0

For example:

$im = imagecreatefrompng("php.png");
$rgb = imagecolorat($im, 10, 15);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;

(from PHP doc)

Color I want to add:

$r2 = rand(0, 255);
$g2 = rand(0, 255);
$b2 = rand(0, 255);

$color = imagecolorallocatealpha($im, $r2, $g2, $b2, 0);        
imagesetpixel($im, 10, 15, $color); 

So the original color ($r, $g, $b) gets replaced with the new color ($r2, $g2, $b2).

But how can I add just a certain amount of $r2, $g2, $b2, not replace completely.

So if the original color is red, and the second random color I generate is green, I want to add only 10% or 15% of the second color.

  • 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-06-13T13:56:03+00:00Added an answer on June 13, 2026 at 1:56 pm

    I haven’t really done much image-processing, so this is just a long shot, but couldn’t you do something like this:

    function addPercentageToNumber($number, $minPercentage, $maxPercentage) {
       return $number + rand( ($number / 100) * $minPercentage, ($number / 100) * $maxPercentage  );
    }
    
    // Base color
    $r2 = rand(0, 255);
    
    // Add 10-20%
    $r2 = addPercentageToNumber($r2, 10, 20);
    

    You would also need to add some code to handle what happens when a result would be >255 and so on. Hope this helps you a little atleast. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Example: http://foo.com/generatepdf.aspx?u=http://foo.com/somepage.aspx?color=blue&size=15 I added the iis tag because I am guessing it also depends
Example Div: <div class=container> <div class=select1></div> <div class=select2></div> <div class=select3></div> </div> Now I want
Example: if I want to upload a video to some video service website (such
I know we can use imagecreatefrompng and imagejpeg functions to convert PNG to JPEG.
I am trying to make this .php file act as a .png, so I
Before I start, I just want to note that I am a PHP noob.
Example: public var myVar:Object; // now I want to get the myVar string //
Example code: # -*- coding: utf-8 -*- from functools import wraps class MyClass(object): def
Example code follows: bool result; result = Operation1(); result &= Operation2(); result &= Operation3();
Example .gitignore: .gitignore .DS_Store .project .pydevproject ... Is it bad to add .gitignore? I

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.