from PIL import Image, ImageFilter, ImageOps Load the logo image from the specified path…
- User
from PIL import Image, ImageFilter, ImageOps
Load the logo image from the specified path
logo_path = '/root/mm/android_final/automated_image_generator/logo.png' logo = Image.open(logo_path).convert("RGBA") # Ensure the logo is in RGBA mode logo_size = logo.size
Create a new blank image for the neon effect
neon_image = Image.new('RGBA', (logo_size[0] + 40, logo_size[1] + 40), (0, 0, 0, 0))
Create the outer edge (stroke) of the logo
logo_mask = logo.convert("L") stroke = ImageOps.expand(logo_mask, border=10, fill=255) # Create a stroke by expanding the image
Apply a blur to the stroke for the neon glow effect
glow = stroke.filter(ImageFilter.GaussianBlur(15))
Function to change colors (simulating neon color change)
def change_neon_color(image, color): # Colorize the glow effect neon_colored = ImageOps.colorize(image.convert("L"), black="black", white=color) return neon_colored
Generate a series of frames with color-shifting neon effects
colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (255, 255, 0), (255, 0, 255), (0, 255, 255)] # RGB colors frames = [] # Store frames for the GIF
for color in colors: # Change the color of the glow effect neon = change_neon_color(glow, color)
# Create an RGBA image to hold the final result final_image = Image.new('RGBA', neon_image.size, (0, 0, 0, 0)) # Transparent background # Create a transparency mask for the neon effect using its alpha channel neon_mask = neon.convert("L") # Create mask from the neon's luminance channel # Paste the neon glow effect onto the final image final_image.paste(neon, (20, 20), neon_mask) # Use neon_mask as the mask # Paste the logo on top of the neon glow final_image.paste(logo, (20, 20), logo) # Original logo retains transparency # Append the final image frame (converted to RGB for GIF) frames.append(final_image.convert("RGB"))Save the frames as an animated GIF
frames[0].save('neon_logo.gif', save_all=True, append_images=frames[1:], duration=200, loop=0)
print("Animated GIF saved as neon_logo.gif") Fix, trung to create a neon effect to a logo that will become a gif and then laid over image
- Assistant