Created
August 12, 2014 19:33
-
-
Save cnlpete/83fcc0b6d2bc0454ca83 to your computer and use it in GitHub Desktop.
metapixel-helper to gather images and sort them via metapixel-sizesort and afterwards use prepare them via metapixel-prepare with appropriate aspect ratios
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
convert=/usr/bin/convert | |
metapixelsizesort=/usr/bin/metapixel-sizesort | |
dir=$1 | |
targetdir=$2 | |
root=`pwd` | |
mkdir -p ${targetdir}/gathering | |
mkdir ${targetdir}/sizesort | |
for i in ${dir}/**/*.jpg | |
do | |
MD5i=`echo "$i" | md5sum | cut -d ' ' -f 1` | |
echo "$convert \"$i\" $convertopts \"${targetdir}/${MD5i}.jpg\"" | |
$convert "$i" -auto-orient -resize 710 "${targetdir}/gathering/${MD5i}.jpg" | |
done | |
$metapixelsizesort -r 2 ${targetdir}/gathering ${targetdir}/sizesort |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
metapixelprepare=/usr/bin/metapixel-prepare | |
dir=$1 | |
targetdir=$2 | |
root=`pwd` | |
size=128 | |
# Default scale used by float functions. | |
float_scale=2 | |
##################################################################### | |
# Evaluate a floating point number expression. | |
function float_eval() | |
{ | |
local stat=0 | |
local result=0.0 | |
if [[ $# -gt 0 ]]; then | |
result=$(echo "scale=$float_scale; $*" | bc -q 2>/dev/null) | |
stat=$? | |
if [[ $stat -eq 0 && -z "$result" ]]; then stat=1; fi | |
fi | |
echo $result | |
return $stat | |
} | |
# Evaluate a floating point number conditional expression. | |
function float_cond() | |
{ | |
local cond=0 | |
if [[ $# -gt 0 ]]; then | |
cond=$(echo "$*" | bc -q 2>/dev/null) | |
if [[ -z "$cond" ]]; then cond=0; fi | |
if [[ "$cond" != 0 && "$cond" != 1 ]]; then cond=0; fi | |
fi | |
local stat=$((cond == 0)) | |
return $stat | |
} | |
mkdir ${targetdir} | |
for i in ${dir}/sizesort/ratio_* | |
do | |
current_ratio=`echo "$i" | cut -d "_" -f 2` | |
vart=$(float_eval "$current_ratio + 2") | |
if float_cond "$current_ratio < 1.0"; then | |
thisheight=$(float_eval "($size / $current_ratio) - 0.5") | |
thiswidth=$size | |
thisheight=${thisheight/.*} | |
else | |
thisheight=$size | |
set -f | |
thiswidth=$(float_eval "($size * $current_ratio) - 0.5") | |
thiswidth=${thiswidth/.*} | |
set +f | |
fi | |
echo "$metapixelprepare -r --height=$thisheight --width=$thiswidth ${i} ${targetdir}" | |
$metapixelprepare -r --height=$thisheight --width=$thiswidth ${i} ${targetdir} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment