-
Notifications
You must be signed in to change notification settings - Fork 0
/
vertical_scroll
97 lines (72 loc) · 3.91 KB
/
vertical_scroll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from PIL import Image, ImageFilter
import glob
import random
import logging
import subprocess
from moviepy.editor import ImageClip, VideoClip
import os
# Set up logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
def feather_image(image, radius=50):
"""Applies a feathered transparency effect to the top and bottom edges of an image."""
logging.info(f"Applying feather effect with radius {radius} to image of size {image.size}")
# Create an alpha mask with the same size as the image
mask = Image.new("L", image.size, 0)
# Apply feathering to the top and bottom edges
mask.paste(255, (0, radius, image.width, image.height - radius))
mask = mask.filter(ImageFilter.GaussianBlur(radius))
# Apply the mask to the image
image.putalpha(mask)
return image
def create_vertical_seamless_image(images, feather_radius=5, overlap=100):
"""Creates a seamless vertical image by stacking the provided images with feathered edges and overlap."""
total_height = sum(img.height for img in images) - overlap * (len(images) - 1)
max_width = max(img.width for img in images)
logging.info(f"Creating combined vertical image of size {max_width}x{total_height}")
# Create a new image with the max width and total height
combined_image = Image.new("RGBA", (max_width, total_height))
y_offset = 0
for i, img in enumerate(images):
feathered_img = feather_image(img, feather_radius)
combined_image.paste(feathered_img, (0, y_offset), feathered_img)
y_offset += img.height - overlap # Overlap the images to ensure they blend seamlessly
logging.info(f"Image {i+1} pasted at position {y_offset}")
return combined_image
# Load your images
image_files = glob.glob('static/archived-store/*.png')+glob.glob('static/archived-store/*.jpg')
# Sort the images by date created
image_files.sort(key=os.path.getmtime, reverse=True)
if len(image_files) < 8:
logging.warning("Less than 8 images found. Adjusting the number of selected images.")
# Resize images to ensure consistency
images = [Image.open(img).convert('RGBA').resize((512, 768), resample=Image.LANCZOS) for img in image_files]
# Create the vertical seamless image
vertical_seamless_image = create_vertical_seamless_image(images, feather_radius=10, overlap=100)
output_path = 'static/vertical_seamless_image.png'
vertical_seamless_image.save(output_path)
logging.info(f"Vertical seamless image saved as {output_path}")
def make_scrolling_video(image_path, output_video_path, video_duration=10, video_size=(512, 768)):
"""Creates a video by scrolling vertically across the image from bottom to top."""
logging.info(f"Loading image from {image_path}")
# Load the image
image = ImageClip(image_path)
def scroll_func(get_frame, t):
"""Defines the scrolling effect by moving the image vertically from bottom to top."""
y = int((image.size[1] - video_size[1]) * (1 - t / video_duration))
return get_frame(t)[y:y+video_size[1], 0:video_size[0]]
# Create the video clip with the scrolling effect
video = VideoClip(lambda t: scroll_func(image.get_frame, t), duration=video_duration)
# Set the frames per second
video = video.set_fps(24)
# Write the video file
logging.info(f"Saving video to {output_video_path}")
video.write_videofile(output_video_path, codec='libx264', audio=False)
# Define the paths and parameters
image_path = 'static/vertical_seamless_image.png'
output_video_path = 'static/vertical_seamless_video.mp4'
video_duration = 34 # duration of the video in seconds
video_size = (512, 768) # size of the output video
# Create the scrolling video
make_scrolling_video(image_path, output_video_path, video_duration, video_size)
# Add a frame to the video using the add_frameL tool
subprocess.run(["/home/jack/miniconda3/envs/cloned_base/bin/python", "add_frameV", output_video_path])