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 = 'logo.png' # Replace with your actual logo path logo = Image.open(logo_path).convert("RGBA") # Ensure the logo is in RGBA mode logo_size = logo.size
Load the background image
background_path = 'background.jpg' # Replace with your actual background image path background = Image.open(background_path).convert("RGBA") bg_width, bg_height = background.size
Calculate the size of the neon effect image
neon_width = logo_size[0] + 40 # Adding extra space for the glow neon_height = logo_size[1] + 40
Ensure the background is large enough to hold the neon effect
if bg_width < neon_width or bg_height < neon_height: bg_width = max(bg_width, neon_width) bg_height = max(bg_height, neon_height) background = background.resize((bg_width, bg_height))
Create the outer edge (stroke) of the logo
logo_mask = logo.convert("L") # Convert logo to grayscale for mask stroke = ImageOps.expand(logo_mask, border=10, fill=255) # Create a stroke by expanding the mask
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 with the specified color neon_colored = ImageOps.colorize(image, black=(0, 0, 0), white=color) return neon_colored
Generate a series of frames with color-shifting neon effects
colors = [ (255, 0, 0), # Red (0, 255, 0), # Green (0, 0, 255), # Blue (255, 255, 0), # Yellow (255, 0, 255), # Magenta (0, 255, 255) # Cyan ] frames = [] # Store frames for the GIF
for color in colors: # Change the color of the glow effect neon = change_neon_color(glow, color)
code# Start with a copy of the background image for each frame final_image = background.copy() # Calculate positions to center the neon effect on the background x = (bg_width - neon_width) // 2 y = (bg_height - neon_height) // 2 # Paste the neon glow effect onto the final image neon_mask = neon.convert("L") # Create mask from the neon's luminance channel final_image.paste(neon, (x, y), neon_mask) # Use neon_mask as the mask # Paste the logo on top of the neon glow final_image.paste(logo, (x + 20, y + 20), logo) # Offset by 20 to account for the border # Append the final image frame (converted to RGB for GIF) frames.append(final_image.convert("RGB")) - Assistant