{"id":3690,"date":"2024-03-15T16:03:50","date_gmt":"2024-03-16T00:03:50","guid":{"rendered":"https:\/\/crm270s.abramjmeister.com\/?p=3690"},"modified":"2024-03-15T16:03:50","modified_gmt":"2024-03-16T00:03:50","slug":"primafinancial-loan-rates-png-color-change-python-code","status":"publish","type":"post","link":"https:\/\/crm270s.mycpamytax.com\/?p=3690","title":{"rendered":"PrimaFinancial Loan Rates .png color change Python Code"},"content":{"rendered":"\n<p class=\"has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-1 wp-block-paragraph\"><strong>red to blue:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from PIL import Image\nimport colorsys\n\ndef rgb_to_hsv(r, g, b):\n    # Convert RGB values to HSV\n    h, s, v = colorsys.rgb_to_hsv(r \/ 255.0, g \/ 255.0, b \/ 255.0)\n    return h, s, v\n\ndef hsv_to_rgb(h, s, v):\n    # Convert HSV values to RGB\n    r, g, b = colorsys.hsv_to_rgb(h, s, v)\n    return int(r * 255), int(g * 255), int(b * 255)\n\ndef change_red_to_blue(image_path, output_path):\n    # Open the image\n    img = Image.open(image_path)\n\n    # Convert the image to RGB mode (if it's not already)\n    img = img.convert(\"RGB\")\n\n    # Get the width and height of the image\n    width, height = img.size\n\n    # Iterate through each pixel in the image\n    for x in range(width):\n        for y in range(height):\n            # Get the RGB values of the pixel\n            r, g, b = img.getpixel((x, y))\n\n            # Convert RGB to HSV\n            h, s, v = rgb_to_hsv(r, g, b)\n\n            # Check if the pixel is red (adjust the threshold as needed)\n            if (h &lt; 0.05 or h &gt; 0.95) and s &gt; 0.5 and v &gt; 0.5:\n                # Change the pixel color to blue\n                img.putpixel((x, y), (0, 0, 255))\n\n    # Save the modified image\n    img.save(output_path)\n    \n    # Close the image file\n    img.close()\n\nif __name__ == \"__main__\":\n    # Specify the input and output file paths\n    input_image_path = \"prima_up_blue_down_red.png\"\n    output_image_path = \"blue_version.png\"\n\n    try:\n        # Change red to blue\n        change_red_to_blue(input_image_path, output_image_path)\n        print(\"Output image saved successfully.\")\n    except Exception as e:\n        print(\"An error occurred while saving the output image:\", e)\n<\/code><\/pre>\n\n\n\n<p class=\"has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-2 wp-block-paragraph\"><strong>green to red:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from PIL import Image\nimport colorsys\n\ndef rgb_to_hsv(r, g, b):\n# Convert RGB values to HSV\n    h, s, v = colorsys.rgb_to_hsv(r \/ 255.0, g \/ 255.0, b \/ 255.0)\n    return h, s, v\n\ndef hsv_to_rgb(h, s, v):\n# Convert HSV values to RGB\n    r, g, b = colorsys.hsv_to_rgb(h, s, v)\n    return int(r * 255), int(g * 255), int(b * 255)\n\ndef change_red_to_blue(image_path, output_path):\n# Open the image\n    img = Image.open(image_path)\n\n# Convert the image to RGB mode (if it's not already)\n    img = img.convert(\"RGB\")\n\n# Get the width and height of the image\n    width, height = img.size\n\n# Iterate through each pixel in the image\n    for x in range(width):\n        for y in range(height):\n        # Get the RGB values of the pixel\n            r, g, b = img.getpixel((x, y))\n\n        # Convert RGB to HSV\n            h, s, v = rgb_to_hsv(r, g, b)\n\n        # Check if the pixel is green (adjust the threshold as needed)\n            if (h > 0.2 and h &lt; 0.4) and (s > 0.3 and s &lt; 0.7) and (v > 0.3 and v &lt; 0.7):\n            # Change the pixel color to red\n                img.putpixel((x, y), (255, 0, 0))\n\n# Save the modified image\n    img.save(output_path)\n\n# Close the image file\n    img.close()\nif __name__ == \"__main__\":\n    # Specify the input and output file paths\n    input_image_path = \"red_to_blue_version.png\"\n    output_image_path = \"green_to_red_version.png\"\n\n    try:\n        # Change red to blue\n        change_red_to_blue(input_image_path, output_image_path)\n        print(\"Output image saved successfully.\")\n    except Exception as e:\n        print(\"An error occurred while saving the output image:\", e)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>red to blue: green to red:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[26],"tags":[],"class_list":["post-3690","post","type-post","status-publish","format-standard","hentry","category-codes"],"_links":{"self":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/posts\/3690","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3690"}],"version-history":[{"count":0,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=\/wp\/v2\/posts\/3690\/revisions"}],"wp:attachment":[{"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3690"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3690"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/crm270s.mycpamytax.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3690"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}