# Having fun with mb-polaroid (conky)

**URL:** https://forum.maboxlinux.org/t/having-fun-with-mb-polaroid-conky/1787
**Category:** Scripts, Tutorials & Tips
**Created:** [October 15, 2024, 9:19pm UTC](https://forum.maboxlinux.org/t/having-fun-with-mb-polaroid-conky/1787 "2024-10-15T21:19:06Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![muzqs](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/muzqs/32/3702_2.png) [@muzqs](https://forum.maboxlinux.org/u/muzqs)
#### Post date: [October 15, 2024, 9:19pm UTC](https://forum.maboxlinux.org/t/having-fun-with-mb-polaroid-conky/1787/1 "2024-10-15T21:19:06Z")

</div>

### 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](https://forum.maboxlinux.org/uploads/default/original/2X/b/b0419ecaaff796ac89dac09df9b734b871391891.gif)

~/.config/conky/menuscripts/polaroid\_slideshow

```auto
#!/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

```auto
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…  
🐦

---

<div class="post-metadata">

### Author: ![muzqs](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/muzqs/32/3702_2.png) [@muzqs](https://forum.maboxlinux.org/u/muzqs)
#### Post date: [October 16, 2024, 8:14am UTC](https://forum.maboxlinux.org/t/having-fun-with-mb-polaroid-conky/1787/2 "2024-10-16T08:14:58Z")

</div>

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

_speeded-up gif_…  
 ![mabox-animation-10-11-22](https://forum.maboxlinux.org/uploads/default/original/2X/7/720e8cbb5aabba646d5ca197705f46dd476c74af.gif)

🐦

---

<div class="post-metadata">

### Author: ![muzqs](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/muzqs/32/3702_2.png) [@muzqs](https://forum.maboxlinux.org/u/muzqs)
#### Post date: [October 16, 2024, 9:25am UTC](https://forum.maboxlinux.org/t/having-fun-with-mb-polaroid-conky/1787/3 "2024-10-16T09:25:13Z")

</div>

New script set random layout every change …

![mabox-animation-11-24-13](https://forum.maboxlinux.org/uploads/default/original/2X/1/1d93e82f6b65f75dad3902184b964e8141379fab.gif)

🐦

---

<div class="post-metadata">

### Author: ![muzqs](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/muzqs/32/3702_2.png) [@muzqs](https://forum.maboxlinux.org/u/muzqs)
#### Post date: [October 23, 2024, 9:29am UTC](https://forum.maboxlinux.org/t/having-fun-with-mb-polaroid-conky/1787/4 "2024-10-23T09:29:43Z")

</div>

### Added scripts…

##### Size 800x600 12 pics… generating random spreading layout.

 ![Mabox_20241023-11-41-38](https://forum.maboxlinux.org/uploads/default/original/2X/5/5de0dcdce1be7873cb7ce551e2f67af83dcf1d96.jpeg)

.conkyrc

```auto
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…

```auto
#!/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.  
🐦

---

<div class="post-metadata">

### Author: ![muzqs](https://forum.maboxlinux.org/user_avatar/forum.maboxlinux.org/muzqs/32/3702_2.png) [@muzqs](https://forum.maboxlinux.org/u/muzqs)
#### Post date: [November 7, 2024, 2:56pm UTC](https://forum.maboxlinux.org/t/having-fun-with-mb-polaroid-conky/1787/5 "2024-11-07T14:56:50Z")

</div>

> [@muzqs](#):
>
> edit 07 nov 2024 : UPDATE bash script. More random placement.

Update: Placement polaroids aerea.

🐦
