Having fun with mb-polaroid (conky)

Having fun with polaroid conky.

For me it is usefull/fun because of many images from a directory. (ripped animations themes)

Polaroid_slideshow : Random images from mbwallpaper.conf $wallpaper_dir.
easy to change position/layout of polaroids
(workspace/alignment given by conkyrc)

speeded_up gif timelaps
mabox-animation-22-39-04

~/.config/conky/menuscripts/polaroid_slideshow

#!/bin/bash

# It uses the wallpaperdir to show random images
CONFIG_DIR="$HOME/.config/mbwallpaper"
CONF_FILE="$CONFIG_DIR/mbwallpaper.conf"

source <(grep = "$CONF_FILE")

temp_dir="/tmp/polaroid_conky"

# Create a temporary directory to store the processed polaroid images
mkdir -p "${temp_dir}"

# Number of images to display
num_images=4

# Get a list of .png images from the wallpaper directory and shuffle to get random images
mapfile -t WALLDIR < <(find "$wallpaper_dir" -type f -name "*.png" | shuf -n "$num_images")

# Initialize an array to hold the paths of the processed images
pol=()

# Process each selected image with ImageMagick to add the polaroid effect
for image in "${WALLDIR[@]}"; do
    NAME=$(basename "${image}")
    output_file="${temp_dir}/${NAME}"

    # Create a resized image for polaroid processing
    resized_image="/tmp/resized_${NAME}"

    # Resize the image while maintaining aspect ratio
    if magick "${image}" -resize 333x245^ -gravity center -extent 333x245 "$resized_image"; then
        # Create the polaroid with white border
        if magick "$resized_image" -bordercolor white -background none +polaroid "$output_file"; then
            # Add the processed polaroid image to the array
            pol+=("$output_file")
        else
            echo "Error processing polaroid for $image" >&2
        fi
    else
        echo "Error resizing image $image" >&2
    fi

    # Clean up the resized image
    rm -f "$resized_image"
done

# Output the Conky image commands in a 2x2 grid with random angles
positions=(
    "10,0"     # Position for the larger image
    "0,140"    # Position for the smaller images
    "83,160"   # Position for the smaller images
    "166,120"  # Position for the smaller images
)

sizes=(
    "300x160" # Larger size for the first image
    "166x120" # Standard size for the rest
    "166x120" # Standard size for the rest
    "166x120" # Standard size for the rest
)

for index in "${!pol[@]}"; do
    # Only output valid polaroid images
    if [[ -f "${pol[index]}" ]]; then
        # Generate a random angle for rotation
        angle=$(( RANDOM % 10 - 5 ))  # Random angle between -5 and 5 degrees
        # Print the image with the angle and size
        printf "\${image ${pol[index]} -p ${positions[index]} -s ${sizes[index]} -a ${angle}}\n"
    fi
done

Polaroid_mbcolors_slideshow.conkyrc

conky.config = {
-- WINDOW
	own_window = true,
	own_window_type = 'desktop',
	own_window_transparent = true,
	own_window_hints = 'undecorated,below,skip_taskbar,skip_pager,sticky',
	own_window_colour = '#0c0e13',
	own_window_class = 'Conky',
	own_window_title = 'Mabox Polaroid Widget',
    
    alignment = 'bottom_right',
	gap_x = 30,
	gap_y = 60,
	minimum_width = 333,
    minimum_height = 280,

-- FONTS
	use_xft = true,
	xftalpha = 1,
	override_utf8_locale = true,

-- COLORS
	draw_shades = false,
	default_shade_color = '#000000',
	draw_outline = false,
	default_outline_color = '#222222',

	default_color = '#ecedef',
	

-- BORDERS
	draw_borders = false,
-- Stippled borders?
	stippled_borders = 1,
-- border margins
	border_inner_margin = 0,
	border_outer_margin = 0,
-- border width
	border_width = 0,

-- MISC
-- Boolean value, if true, Conky will be forked to background when started.
	background = true,

-- Adds spaces around certain objects to stop them from moving other things
-- around, this only helps if you are using a mono font
-- Options: right, left or none
	use_spacer = 'none',

-- Subtract (file system) buffers from used memory?
	no_buffers = true,

-- Imlib2 image cache size, in bytes. Default 4MiB Increase this value if you use
-- $image lots. Set to 0 to disable the image cache.
	imlib_cache_size = 0,

-- Use the Xdbe extension? (eliminates flicker)
-- It is highly recommended to use own window with this one
-- so double buffer won't be so big.
	double_buffer = true,
	update_interval = 1,
};

conky.text = [[
${execpi 350 ~/.config/conky/menuscripts/polaroid_slideshow}
]];

have fun…
:bird:

2 Likes

Playing with the layout.
Added more polaroids and bigger space.

speeded-up gif…
mabox-animation-10-11-22

:bird:

1 Like

New script set random layout every change …

mabox-animation-11-24-13

:bird:

1 Like

Added scripts…

Size 800x600 12 pics… generating random spreading layout.

.conkyrc

conky.config = {
-- WINDOW
	own_window = true,
	own_window_type = 'desktop',
	own_window_transparent = true,
	own_window_hints = 'undecorated,below,skip_taskbar,skip_pager,sticky',
	own_window_colour = '#0c0e13',
	own_window_class = 'Conky',
	own_window_title = 'Mabox Polaroid Widget',
    
    alignment = 'top_left',
	gap_x = 178,
	gap_y = 589,
	minimum_width = 800,
    minimum_height = 600,

-- FONTS
	use_xft = true,
	xftalpha = 1,
	override_utf8_locale = true,

-- COLORS
	draw_shades = false,
	default_shade_color = '#000000',
	draw_outline = false,
	default_outline_color = '#222222',

	default_color = '#ecedef',
	

-- BORDERS
	draw_borders = false,
-- Stippled borders?
	stippled_borders = 1,
-- border margins
	border_inner_margin = 0,
	border_outer_margin = 0,
-- border width
	border_width = 0,

-- MISC
-- Boolean value, if true, Conky will be forked to background when started.
	background = true,

-- Adds spaces around certain objects to stop them from moving other things
-- around, this only helps if you are using a mono font
-- Options: right, left or none
	use_spacer = 'none',

-- Subtract (file system) buffers from used memory?
	no_buffers = true,

-- Imlib2 image cache size, in bytes. Default 4MiB Increase this value if you use
-- $image lots. Set to 0 to disable the image cache.
	imlib_cache_size = 0,

-- Use the Xdbe extension? (eliminates flicker)
-- It is highly recommended to use own window with this one
-- so double buffer won't be so big.
	double_buffer = true,
	update_interval = 1,
};

conky.text = [[
${execpi 250 ~/.config/conky/menuscripts/polaroid_slideshow}
]];

Polaroid script…

#!/bin/bash

CONFIG_DIR="$HOME/.config/mbwallpaper"
CONF_FILE="$CONFIG_DIR/mbwallpaper.conf"

source <(grep = "$CONF_FILE")

# Set the wallpaper directory : for testing
# wallpaper_dir="/run/media/vogel/mkgifs/CG-Scifi_zombies"
temp_dir="/tmp/polaroid_conky"

# Create a temporary directory to store the processed polaroid images
mkdir -p "${temp_dir}"

# Number of images to display
num_images=12

# Get a list of .png images from the wallpaper directory and shuffle to get random images
mapfile -t WALLDIR < <(find "$wallpaper_dir" -type f -name "*.png" | shuf -n "$num_images")

# Initialize an array to hold the paths of the processed images
pol=()

# Process each selected image with ImageMagick to add the polaroid effect
for image in "${WALLDIR[@]}"; do
    NAME=$(basename "${image}")
    output_file="${temp_dir}/${NAME}"

    # Create a resized image for polaroid processing
    resized_image="/tmp/resized_${NAME}"

    # Resize the image while maintaining aspect ratio
    if magick "${image}" -resize 333x245^ -gravity center -extent 333x245 "$resized_image"; then
        # Create the polaroid with white border
        if magick "$resized_image" -bordercolor black -background none +polaroid "$output_file"; then
            # Add the processed polaroid image to the array
            pol+=("$output_file")
        else
            echo "Error processing polaroid for $image" >&2
        fi
    else
        echo "Error resizing image $image" >&2
    fi

    # Clean up the resized image
    rm -f "$resized_image"
done

# Function to shuffle an array
shuffle_array() {
    local i tmp size max rand
    size=${#positions[@]}
    max=$(( 32768 / size * size ))  # ensures fair shuffling

    for ((i = size - 1; i > 0; i--)); do
        while (( (rand = RANDOM) >= max )); do :; done
        rand=$(( rand % (i + 1) ))
        tmp=${positions[i]}
        positions[i]=${positions[rand]}
        positions[rand]=$tmp
    done
}

# Declare the positions
positions=(
    "340,140"
    "500,180"
    "340,290"
    "400,360"
    "0,140"
    "83,160"
    "166,120"
    "250,0"
    "30,230"
    "83,160"
    "0,0"
    "150,350"
)

# Shuffle the positions
shuffle_array

sizes=(
    "300x160"
    "166x120" 
    "166x120"
    "166x120"
    "300x160" 
    "166x120" 
    "166x120"
    "166x120" 
    "300x160" 
    "166x120" 
    "166x120"
    "166x120"
)


for index in "${!pol[@]}"; do
    # Only output valid polaroid images
    if [[ -f "${pol[index]}" ]]; then
        # Generate a random angle for rotation
        angle=$(( RANDOM % 10 - 5 ))  # Random angle between -5 and 5 degrees
        # Print the image with the angle and size
        printf "\${image ${pol[index]} -p ${positions[index]} -s ${sizes[index]} -a ${angle}}\n"
    fi
done


edit 07 nov 2024 : finetune bash script. More random placement.
:bird:

2 Likes

Update: Placement polaroids aerea.

:bird: