Skip to content

Instantly share code, notes, and snippets.

@tomoe-mami
Last active December 11, 2015 07:19
Show Gist options
  • Save tomoe-mami/4565562 to your computer and use it in GitHub Desktop.
Save tomoe-mami/4565562 to your computer and use it in GitHub Desktop.
A script to convert images within a directory into edje files for E background.
#!/bin/sh
IMAGE_DIR=${1:-.}
OUTPUT_DIR=${2:-~/.e/e/backgrounds}
TEMPLATE='
images { image: "@IMAGE@" USER; }
collections {
group {
name: "e/desktop/background";
data { item: "style" "4"; item: "noanimation" "1"; }
max: @WIDTH@ @HEIGHT@;
parts {
part {
name: "bg";
mouse_events: 0;
description {
state: "default" 0.0;
aspect: @ASPECT@ @ASPECT@;
aspect_preference: NONE;
image { normal: "@IMAGE@"; scale_hint: STATIC; }
}
}
}
}
}
'
IMAGE_DIR="$(realpath "$IMAGE_DIR")"
OUTPUT_DIR="$(realpath "$OUTPUT_DIR")"
cd "$IMAGE_DIR"
for FILENAME in *.{png,jpg}; do
DIMENSION="$(identify -format "%w/%h" "$FILENAME")"
if [ -z "$DIMENSION" ]; then
continue
fi
WIDTH=$(echo $DIMENSION | cut -d/ -f1)
HEIGHT=$(echo $DIMENSION | cut -d/ -f2)
IMAGE="$(echo "$IMAGE_DIR/$FILENAME" | sed 's/[^[:alnum:]_-]/\\&/g')"
if [ -z "$HEIGHT" -o "$HEIGHT" = "0" ]; then
ASPECT="0.0"
else
ASPECT=$(echo "scale=9; $DIMENSION" | bc)
fi
echo "$TEMPLATE" | \
sed "s/@ASPECT@/$ASPECT/g; s/@WIDTH@/$WIDTH/g; s/@HEIGHT@/$HEIGHT/g; s|@IMAGE@|$IMAGE|g" > tmp.edc
edje_cc tmp.edc -o "$OUTPUT_DIR/${FILENAME%.*}.edj"
rm tmp.edc
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment