-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathimageResizeToExactSize.sh
More file actions
executable file
·48 lines (39 loc) · 1.4 KB
/
imageResizeToExactSize.sh
File metadata and controls
executable file
·48 lines (39 loc) · 1.4 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
#!/bin/bash
source @includes.sh
echo '###################################################'
echo '# Description: Resize an image to a exact dimensions'
echo '# Usage: $ ./imageResizeToExactSize.sh /Absolute/image/file.jpg 1024 512'
echo '# Param 1: Image file'
echo '# Param 2: Width'
echo '# Param 3: Height'
echo '# Requires: Imagemagick'
echo '###################################################'
echoNewline
################################################################################
################################################################################
# check parameters
if [[ $1 == "" ]] ; then
echoError '1st arg must be an image file'
exit 1
fi
if [[ $2 -eq 0 ]] ; then
echoError '2nd arg must be width'
exit 1
fi
if [[ $3 -eq 0 ]] ; then
echoError '3rd arg must be height'
exit 1
fi
################################################################################
################################################################################
# get filename
filename=$1
extension=$(extension $filename)
echoInfo "Resizing image: $filename"
outputFile="$1.$2x$3.$extension"
# do conversion
convert $1 -resize $2x$3\! $outputFile
################################################################################
################################################################################
# complete
echoSuccess "Success: Image resized to exact dimension of: $2x$3 \n# $outputFile"