Last active
December 19, 2015 14:18
-
-
Save polymorphm/5967881 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# -*- mode: sh; coding: utf-8 -*- | |
milanta_pict_conv__pict_conv () { | |
ico_width="160" | |
ico_height="120" | |
in_path="$1" | |
in_basename="$(basename -- "$in_path")" | |
in_name="${in_basename%\.*}" | |
in_dir="$(dirname -- "$in_path")" | |
tmp_dir="$in_dir/../milanta_pict_conv.tmp" | |
ico_dir="$in_dir/../ico" | |
ico_path="$ico_dir/$in_name.jpg" | |
ful_dir="$in_dir/../ful" | |
ful_path="$ful_dir/$in_name.jpg" | |
if [ ! -f "$in_path" ] | |
then | |
false | |
return | |
fi | |
mkdir -p -- "$tmp_dir" | |
if ! convert -resize "$[ico_width]" "$in_path" "$tmp_dir/$in_name.ico_1.png" | |
then | |
false | |
return | |
fi | |
if ! convert -resize "x$[ico_height]" "$in_path" "$tmp_dir/$in_name.ico_2.png" | |
then | |
false | |
return | |
fi | |
ico_1_size=$[$(stat -c %s -- "$tmp_dir/$in_name.ico_1.png")] | |
ico_2_size=$[$(stat -c %s -- "$tmp_dir/$in_name.ico_2.png")] | |
if ! ((ico_1_size)) | |
then | |
false | |
return | |
fi | |
if ! ((ico_2_size)) | |
then | |
false | |
return | |
fi | |
if ((ico_1_size >= ico_2_size)) | |
then | |
if ! convert -gravity center -crop "$[ico_width]x$[ico_height]+0+0" "$tmp_dir/$in_name.ico_1.png" "$tmp_dir/$in_name.ico_3.png" | |
then | |
false | |
return | |
fi | |
else | |
if ! convert -gravity center -crop "$[ico_width]x$[ico_height]+0+0" "$tmp_dir/$in_name.ico_2.png" "$tmp_dir/$in_name.ico_3.png" | |
then | |
false | |
return | |
fi | |
fi | |
mkdir -p -- "$ico_dir" | |
mkdir -p -- "$ful_dir" | |
if ! convert -strip -interlace plane "$tmp_dir/$in_name.ico_3.png" "$ico_path" | |
then | |
false | |
return | |
fi | |
if ! convert -resize "1000x1000>" "$in_path" "$ful_path" | |
then | |
false | |
return | |
fi | |
} | |
milanta_pict_conv__bulk_pict_conv () { | |
for arg | |
do | |
milanta_pict_conv__pict_conv "$arg" | |
done | |
} | |
milanta_pict_conv__php_escape () { | |
val="$1" | |
val="${val//\\/\\\\}" | |
val="${val//\'/\'}" | |
echo "$val" | |
} | |
milanta_pict_conv__create_item_list () { | |
art_major="$1" | |
shift | |
art_minor="$1" | |
shift | |
echo "'item_list' => array(" | |
for arg | |
do | |
arg_name="$(basename -- "$arg")" | |
echo " array(" | |
echo " 'filename' => '$(milanta_pict_conv__php_escape "$arg_name")'," | |
echo " 'text' => 'art.$[art_major].$[art_minor]'," | |
echo " )," | |
((++art_minor)) | |
done | |
echo " )," | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment