#!/bin/bash

find . -type d -printf "%f\n" > file_list.tmp
sed -i -e 's/^/"/g' -e 's/$/"/g' -e '1d' file_list.tmp

mkdir origin/ converted/
function run_convert(){
        f_in=[email protected]
	f_out=$(echo ${f_in}|sed 's/$/\.zip/g')

        mkdir tmp2/
        find "${f_in}" -name "*.png" -exec cp -l {} tmp2/ \;
        find "${f_in}" -name "*.jpg" -exec cp -l {} tmp2/ \;
        find "${f_in}" -name "*.jpeg" -exec cp -l {} tmp2/ \;
        find "${f_in}" -name "*.gif" -exec cp -l {} tmp2/ \;
        cd tmp2/
        zip -r "../converted/${f_out}" *
        cd ../
        rm -r tmp2
        mv "${f_in}" origin/
}

export -f run_convert
xargs -a file_list.tmp -n 1 bash -c 'run_convert "[email protected]"' _
rm file_list.tmp