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 8846141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:54:23+00:00 2026-06-14T11:54:23+00:00

Is there any way to take a base 64 string, for example: .copyIcon {background:

  • 0

Is there any way to take a base 64 string, for example:

.copyIcon {background: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAW0lEQVR42mNgQALCi7//J4QZcAFiNOM1hJANBA0h1QC83iHFizDJ/dgww/7/LAQNwKUZbkjDfya8YQZXiCqJagilBmAzhLYGYDNsJBhAMD3gS854NS/6vg+fZgDKvmW19S7PRAAAAABJRU5ErkJggg==") center center no-repeat;}

And replace a solid color with another solid color using JavaScript?

In this specific example I have a solid color in the icon (#13A3F7) that I would like to replace with another solid color (#ff6400).

The reason for doing this is it is not a one-off. I would like to be able to change the icon to any color with a setting.

Is there any way I can do this?

  • 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-14T11:54:24+00:00Added an answer on June 14, 2026 at 11:54 am

    Here is a little function which takes 3 parameters: data, colorFrom, colorTo (both colors should be supplied in hex)

    function changeColInUri(data,colfrom,colto) {
        // create fake image to calculate height / width
        var img = document.createElement("img");
        img.src = data;
        img.style.visibility = "hidden";
        document.body.appendChild(img);
    
        var canvas = document.createElement("canvas");
        canvas.width = img.offsetWidth;
        canvas.height = img.offsetHeight;
    
        var ctx = canvas.getContext("2d");
        ctx.drawImage(img,0,0);
    
        // remove image
        img.parentNode.removeChild(img);
    
        // do actual color replacement
        var imageData = ctx.getImageData(0,0,canvas.width,canvas.height);
        var data = imageData.data;
    
        var rgbfrom = hexToRGB(colfrom);
        var rgbto = hexToRGB(colto);
    
        var r,g,b;
        for(var x = 0, len = data.length; x < len; x+=4) {
            r = data[x];
            g = data[x+1];
            b = data[x+2];
    
            if((r == rgbfrom.r) &&
               (g == rgbfrom.g) &&
               (b == rgbfrom.b)) {
    
                data[x] = rgbto.r;
                data[x+1] = rgbto.g;
                data[x+2] = rgbto.b;
    
            } 
        }
    
        ctx.putImageData(imageData,0,0);
    
        return canvas.toDataURL();
    }
    

    An additional function is required to convert hex colors to RGB (for correct matching)

    function hexToRGB(hexStr) {
        var col = {};
        col.r = parseInt(hexStr.substr(1,2),16);
        col.g = parseInt(hexStr.substr(3,2),16);
        col.b = parseInt(hexStr.substr(5,2),16);
        return col;
    }
    

    Usage would be like so:

    changeColInUri(
        "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAW0lEQVR42mNgQALCi7//J4QZcAFiNOM1hJANBA0h1QC83iHFizDJ/dgww/7/LAQNwKUZbkjDfya8YQZXiCqJagilBmAzhLYGYDNsJBhAMD3gS854NS/6vg+fZgDKvmW19S7PRAAAAABJRU5ErkJggg==",
        "#13A3F7",
        "#ff6400"
    );
    

    It will return a new data:image/png; URI with the swapped colors, here is a working jsfiddle of the end result

    http://jsfiddle.net/V5dU2/

    (tested on Chrome, Firefox and IE10)

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

Sidebar

Related Questions

Is there any better way to get take a string such as (123) 455-2344
Is there any way I can take two WinForms elements of the same size/type,
Is there any convenient way to take an array/set of objects and create a
Using jquery UI 1.8's autocomplete, is there any known way to take the results
Is there any way to have to tabcontrol take the size of the largest
Is there any way to open a broadcast bluetooth socket, take a listen and
Is there a way to take any number, from say, 1 to 40000 and
Is there any way to take the video feed from the camera of an
Is there anyway we can take input from command line in Objective-C, the way
I am trying to take the base URL from a site and be able

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.