All pastes #811147 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-12-10 17:22 UTC
rendered paste body
#!/bin/sh

### Settings ###

colorspace=RGB
borderRadius=5
borderColor='#DEBE4A'
borderSize=2
backgroundColor=black
imageSize=110
searchPattern="*cover*.jpg"
ouputName="cover.bmp"

### Script ###
read -p "Enter 'c' to convert and 'r' to remove all covers: " line
line=$(echo $line|cut -c 1)

if [ "$line" = "c" ]; then

    convert -size $borderRadius'x'$borderRadius -fill $borderColor xc:$backgroundColor -draw 'circle 0,0 0,'$(($borderRadius-1)) \
            \( xc:none -draw 'circle 0,0 0,'$(($borderRadius-$borderSize-1)) \) \
            -compose dst_out -composite /tmp/corner.png

    IFS='
'
    finder=$(find . -iname $searchPattern)
    
    count=0
    for file in $finder; do
        count=$(($count + 1))
    done

    i=0
    for file in $finder; do  
        out_file=$(dirname $file)'/'$ouputName
        
        i=$(($i + 1))
        echo 'Converting cover '$i' of '$count' ... ('$out_file')'
        convert $file -resize $(($imageSize - $borderSize*2))'x'$(($imageSize - $borderSize*2)) -colorspace $colorspace $out_file

        convert $out_file -bordercolor $borderColor -border $borderSize -matte \
                \( /tmp/corner.png -flip -flop \) -gravity NorthWest -composite \
                \( /tmp/corner.png       -flop \) -gravity SouthWest -composite \
                \( /tmp/corner.png -flip       \) -gravity NorthEast -composite \
                \( /tmp/corner.png             \) -gravity SouthEast -composite \
                +matte $out_file
    done

    rm /tmp/corner.png

elif [ "$line" = "r" ]; then
    find . -name $ouputName -exec rm -v {} \;
else
    echo "Exit"
    exit 1
fi