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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:51:04+00:00 2026-06-06T03:51:04+00:00

I’m looking for a way to change a color’s tone, knowing it’s RGB composition,

  • 0

I’m looking for a way to change a color’s tone, knowing it’s RGB composition, then replace all instances of the old RGB with the obtained RGB. For example, I’d like red to become purple, light red, light purple, etc…
It can be done in photoshop by changing a color’s hue.

What I’ve thought so far is the following: convert RGB to HLS, then change the Hue.

Here’s the code so far (multiple colors are changed, not just one, defined in the “list” list):

(As you might notice, I’m just a beginner and the code itself is pretty dirty; the cleaner parts are probably taken from other SO users)
Thanks a lot!

import colorsys

from tempfile import mkstemp
from shutil import move
from os import remove, close

def replace(file, pattern, subst):
    #Create temp file
    fh, abs_path = mkstemp()
    new_file = open(abs_path,'w')
    old_file = open(file)
    for line in old_file:
        new_file.write(line.replace(pattern, subst))
    #close temp file
    new_file.close()
    close(fh)
    old_file.close()
    #Remove original file
    remove(file)
    #Move new file
    move(abs_path, file)

def decimal(var):
    return '{:g}'.format(float(var))

list=[[60,60,60],[15,104,150],[143,185,215],[231,231,231],[27,161,253],[43,43,43],[56,56,56],[255,255,255],[45,45,45],[5,8,10],[23,124,193],[47,81,105],[125,125,125],[0,0,0],[24,24,24],[0,109,166],[0,170,255],[127,127,127]]

for i in range(0,len(list)):
    r=list[i][0]/255
    g=list[i][1]/255
    b=list[i][2]/255
    h,l,s=colorsys.rgb_to_hls(r,g,b)
    print(decimal(r*255),decimal(g*255),decimal(b*255))
    h=300/360
    str1=str(decimal(r*255)) + "," + str(decimal(g*255)) + "," + str(decimal(b*255))
    r,g,b=colorsys.hls_to_rgb(h, l, s)
    print(decimal(r*255),decimal(g*255),decimal(b*255))
    str2=str(decimal(r*255)) + "," + str(decimal(g*255)) + "," + str(decimal(b*255))
    replace("Themes.xml",str1,str2)

EDIT: The problem was pretty simple: R,G,B and H must be between 0 and 1, I was setting them between 0 and 255 and 0 and 360. Updated code.

  • 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-06T03:51:05+00:00Added an answer on June 6, 2026 at 3:51 am

    Your sequence of colors uses integers, but colorsys uses floating point values between 0.0 and 1.0. Divide all the numbers by 255. before putting them through, then multiply by 255 and truncate after getting them back.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.