-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreaderUpSizer.sh
More file actions
142 lines (110 loc) · 3.88 KB
/
readerUpSizer.sh
File metadata and controls
142 lines (110 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/bin/bash
# Requirements: Linux bash/ImageMagick
# 17 1024X768 in 8 secs with 100 quality, 30000 around 4 hours
# You can edit these settings:
# Default source
default_src="3.txt";
# Default destination
default_dst="2";
# Output JPG quality: maximum is 100 (recommended)
default_qua="100"
# Minimum width to resize greater than that
default_min_width="400"
# Maximum width to resize greater than that
default_max_width="600"
function resize(){
echo "Conversion started..."
# Setup arguments/sharpen/unsharp/quality parameters
local argument1="-filter sinc -define filter:support=5 -resize 800"
local argument2="-filter sinc -resize 800 -unsharp 0x0.5+0.8"
local sharpen="-sharpen 0x1"
local quality="-quality ${qua}"
local COUNTER=0
local last_resized=""
# to make the script read white spaces
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
while read line
do
echo "Checking ${line}"
# create line with %20 instead of space
lineNoSpace=${line// /%20}
# Detect source image width and height
src_w=$(identify -format "%w" "${lineNoSpace}")
# Go to the next iteration if error
if [ $? != 0 ]; then
echo "${line} not accessible, moving to errorLog.txt"
echo $line >> $dst/errorLog.txt
continue
fi
src_h=$(identify -format "%h" "${lineNoSpace}")
# If the image considered large
if ((${src_w} > ${defMinWidth} && ${src_w} < ${defMaxWidth})); then
echo "Qualified to be resized, dimentions: ${src_w} X ${src_h}"
# Resize, sharpen
echo "processing ${line}"
# Creating the path
local temp=${line}
# Take the file name out
local trimedPath=${temp%/*}
# Take the http:// out
local path=${trimedPath#*/}
if [[ ! -e $dst${path} ]]; then
echo "Creating path $dst$path"
mkdir -p $dst${path}
fi
if [[ ! -e $dst${path}/large ]]; then
mkdir $dst${path}/large
fi
if [[ ! -e $dst${path}/error ]]; then
mkdir $dst${path}/error
fi
# Not using the arguments because it errors out when try to handle spaces in the entry name
convert ${lineNoSpace} -filter sinc -define filter:support=5 -resize 800 $dst${path}/large/$(basename $line)
# If the last command result has error
if [ $? == 0 ]; then
COUNTER=$((COUNTER+1))
echo "Conversion successful"
echo ""
else
echo "Sending to error directory"
cp ${line} $dst${path}/error/$(basename $line)
fi
last_resized=${line}
fi
done < ${src}
# Set the IFS back to normal
IFS=$SAVEIFS
echo "Last resized image: ${last_resized}"
echo "Number of files resized: ${COUNTER}"
}
# Ask for source image, or use default value
echo "Welcome, add a line to the beginning and end of text file to make sure they won't be skipped!"
echo "Enter source path text file (.txt)/Enter to keep default (${default_src}): "
read src
src=${src:-${default_src}}
# Ask for destination path, or use default value
echo "Enter destination path/Enter to keep default (${default_dst}):"
read dst
dst=${dst:-${default_dst}}
# Ask for Minimum Width, or use default value
echo "Enter Minimum Width (to resize between Minimum/Enter to keep default (${default_min_width}):"
read defMinWidth
defMinWidth=${defMinWidth:-${default_min_width}}
# Ask for Maximum Width, or use default value
echo "Enter Maximum Width (and Maximum/Enter to keep default (${default_max_width}):"
read defMaxWidth
defMaxWidth=${defMaxWidth:-${default_max_width}}
# Ask for quality, or use default value
echo "Enter quality/Enter to keep default (${default_qua}):"
read qua
qua=${qua:-${default_qua}}
# Create the destination path
if [[ ! -e $dst ]]; then
echo "Making ${dst} Directory..."
mkdir $dst
fi
# Call the resize function
resize
# Done!
echo "Done!"