import json
import logging
from PIL import Image, ImageDraw, ImageFilter
import os

def load_config(config_path):
    with open(config_path, 'r') as file:
        return json.load(file)

def setup_logging(log_file_path, level=logging.INFO):
    logging.basicConfig(
        filename=log_file_path,
        level=level,
        format='%(asctime)s - %(levelname)s - %(message)s'
    )
    logging.info("Logging is set up.")

def apply_glow_effect(image, padding, blur_radius, colors):
    width, height = image.size
    glow_images = []
    
    for color in colors:
        # Create a new image for the glow effect
        glow = Image.new('RGBA', (width + padding * 2, height + padding * 2), (0, 0, 0, 0))
        draw = ImageDraw.Draw(glow)

        # Draw the image on the glow canvas
        draw.bitmap((padding, padding), image, fill=(255, 255, 255))
        
        # Apply blur effect
        glow = glow.filter(ImageFilter.GaussianBlur(blur_radius))
        
        # Set the color and alpha for the glow
        for x in range(glow.width):
            for y in range(glow.height):
                r, g, b, a = glow.getpixel((x, y))
                glow.putpixel((x, y), (int(r * (color[0] / 255)), 
                                        int(g * (color[1] / 255)), 
                                        int(b * (color[2] / 255)), 
                                        a))
        
        glow_images.append(glow)
    
    return glow_images

def create_gif(glow_images, output_gif_path, frame_duration_ms, loop, optimize):
    glow_images[0].save(
        output_gif_path,
        save_all=True,
        append_images=glow_images[1:],
        duration=frame_duration_ms,
        loop=loop,
        optimize=optimize
    )
    logging.info(f"GIF created at {output_gif_path}")

def main():
    # Load configuration
    config_path = 'config.json'  # Path to your neon_logo.py config file
    config = load_config(config_path)

    # Set up logging
    setup_logging(config['paths']['log_file_path'], logging.INFO)

    try:
        # Load logo and background images
        logo_path = config['paths']['logo_path']
        background_path = config['paths']['background_path']
        
        logo_image = Image.open(logo_path).convert('RGBA')
        background_image = Image.open(background_path).convert('RGBA')

        # Apply glow effect
        glow_images = apply_glow_effect(
            logo_image, 
            config['glow_effect']['padding'], 
            config['glow_effect']['blur_radius'], 
            config['glow_effect']['colors']
        )

        # Combine background and glow images
        combined_images = []
        for glow in glow_images:
            combined = Image.alpha_composite(background_image, glow)
            combined_images.append(combined)

        # Create GIF
        create_gif(
            combined_images, 
            config['paths']['output_gif_path'], 
            config['gif_settings']['frame_duration_ms'], 
            config['gif_settings']['loop'], 
            config['gif_settings']['optimize']
        )

    except Exception as e:
        logging.error(f"Error occurred: {e}")

if __name__ == '__main__':
    main()
{24-10-12 16:30}localhost:~/mm/py_ad/scripts root# python3 neon_logo.py
Traceback (most recent call last):
  File "/root/mm/py_ad/scripts/neon_logo.py", line 100, in <module>
    main()
  File "/root/mm/py_ad/scripts/neon_logo.py", line 60, in main
    config = load_config(config_path)
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/mm/py_ad/scripts/neon_logo.py", line 8, in load_config
    return json.load(file)
           ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/__init__.py", line 293, in load
    return loads(fp.read(),
           ^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 11 column 28 (char 387)