Skip to main content
Code Review

Return to Question

Commonmark migration
Source Link

I use ImageMagick to crop image, encapsulate the related code to functions.

Here is the code:

convertc2(){
 convert 1ドル -crop 2ドル "two.png"
}
converto3(){
 Delimeter="placeHolder"
 if [[ 2ドル == *"x"* ]]; then
 Delimeter="x"
 else
 Delimeter="X"
 fi
 First="${2%$Delimeter*}"
 Fourth="${2##*+}"
 Lhs="${2%%+*}"
 Rhs="${2#"$Lhs+"}"
 Second="${Lhs##*$Delimeter}"
 Third="${Rhs%+*}"
 One=$(echo "scale=0 ; $First * 1.5" | bc)
 One=${One%.*}
 Two=$(echo "$Second * 1.5" | bc)
 Two=${Two%.*}
 Three=$(echo "$Third * 1.5" | bc)
 Three=${Three%.*}
 Four=$(echo "$Fourth * 1.5" | bc)
 Four=${Four%.*}
 Final=$One"X"$Two"+"$Three"+"$Four
 echo $Final
 convert 1ドル -crop $Final "three.png"
}

Usage like this:

convertc2 /Users/dengjiangzhou/Desktop/Simulator\ Screen\ Shot\ -\ iPhone\ 8\ -\ 2019年02月20日\ at\ 14.39.02.png 300X300+0+0 
converto3 /Users/dengjiangzhou/Desktop/Simulator\ Screen\ Shot\ -\ iPhone\ 8\ -\ 2019年02月20日\ at\ 14.39.02.png 300X300+0+0 

I need the image size of @2X and @3X. So the function converto3 use convertc2 's size and transform to its size.

Delimeter="placeHolder"
 
if [[ 2ドル == *"x"* ]]; then
 Delimeter="x"
else
 Delimeter="X"
fi

I really care about how to improve the above code. The "x" , I may type "X" or "x".

how to use this "${2%$Delimeter*}" insensitive?

And the calculation code in converto3() is very ugly.

I use ImageMagick to crop image, encapsulate the related code to functions.

Here is the code:

convertc2(){
 convert 1ドル -crop 2ドル "two.png"
}
converto3(){
 Delimeter="placeHolder"
 if [[ 2ドル == *"x"* ]]; then
 Delimeter="x"
 else
 Delimeter="X"
 fi
 First="${2%$Delimeter*}"
 Fourth="${2##*+}"
 Lhs="${2%%+*}"
 Rhs="${2#"$Lhs+"}"
 Second="${Lhs##*$Delimeter}"
 Third="${Rhs%+*}"
 One=$(echo "scale=0 ; $First * 1.5" | bc)
 One=${One%.*}
 Two=$(echo "$Second * 1.5" | bc)
 Two=${Two%.*}
 Three=$(echo "$Third * 1.5" | bc)
 Three=${Three%.*}
 Four=$(echo "$Fourth * 1.5" | bc)
 Four=${Four%.*}
 Final=$One"X"$Two"+"$Three"+"$Four
 echo $Final
 convert 1ドル -crop $Final "three.png"
}

Usage like this:

convertc2 /Users/dengjiangzhou/Desktop/Simulator\ Screen\ Shot\ -\ iPhone\ 8\ -\ 2019年02月20日\ at\ 14.39.02.png 300X300+0+0 
converto3 /Users/dengjiangzhou/Desktop/Simulator\ Screen\ Shot\ -\ iPhone\ 8\ -\ 2019年02月20日\ at\ 14.39.02.png 300X300+0+0 

I need the image size of @2X and @3X. So the function converto3 use convertc2 's size and transform to its size.

Delimeter="placeHolder"
 
if [[ 2ドル == *"x"* ]]; then
 Delimeter="x"
else
 Delimeter="X"
fi

I really care about how to improve the above code. The "x" , I may type "X" or "x".

how to use this "${2%$Delimeter*}" insensitive?

And the calculation code in converto3() is very ugly.

I use ImageMagick to crop image, encapsulate the related code to functions.

Here is the code:

convertc2(){
 convert 1ドル -crop 2ドル "two.png"
}
converto3(){
 Delimeter="placeHolder"
 if [[ 2ドル == *"x"* ]]; then
 Delimeter="x"
 else
 Delimeter="X"
 fi
 First="${2%$Delimeter*}"
 Fourth="${2##*+}"
 Lhs="${2%%+*}"
 Rhs="${2#"$Lhs+"}"
 Second="${Lhs##*$Delimeter}"
 Third="${Rhs%+*}"
 One=$(echo "scale=0 ; $First * 1.5" | bc)
 One=${One%.*}
 Two=$(echo "$Second * 1.5" | bc)
 Two=${Two%.*}
 Three=$(echo "$Third * 1.5" | bc)
 Three=${Three%.*}
 Four=$(echo "$Fourth * 1.5" | bc)
 Four=${Four%.*}
 Final=$One"X"$Two"+"$Three"+"$Four
 echo $Final
 convert 1ドル -crop $Final "three.png"
}

Usage like this:

convertc2 /Users/dengjiangzhou/Desktop/Simulator\ Screen\ Shot\ -\ iPhone\ 8\ -\ 2019年02月20日\ at\ 14.39.02.png 300X300+0+0 
converto3 /Users/dengjiangzhou/Desktop/Simulator\ Screen\ Shot\ -\ iPhone\ 8\ -\ 2019年02月20日\ at\ 14.39.02.png 300X300+0+0 

I need the image size of @2X and @3X. So the function converto3 use convertc2 's size and transform to its size.

Delimeter="placeHolder"
 
if [[ 2ドル == *"x"* ]]; then
 Delimeter="x"
else
 Delimeter="X"
fi

I really care about how to improve the above code. The "x" , I may type "X" or "x".

how to use this "${2%$Delimeter*}" insensitive?

And the calculation code in converto3() is very ugly.

edited tags; edited title
Link
200_success
  • 145.5k
  • 22
  • 190
  • 479

Bash function , extract word from stringto produce variants of images at 2X and code adjustment3X resolutions

added 2 characters in body
Source Link
janos
  • 112.9k
  • 15
  • 154
  • 396

I use ImageMagick to crop image, encapsulate the related code to functions.

Here is the code:

convertc2(){
 convert 1ドル -crop 2ドル "two.png"
}
converto3(){
 Delimeter="placeHolder"
 if [[ 2ドル == *"x"* ]]; then
 Delimeter="x"
 else
 Delimeter="X"
 fi
 First="${2%$Delimeter*}"
 Fourth="${2##*+}"
 Lhs="${2%%+*}"
 Rhs="${2#"$Lhs+"}"
 Second="${Lhs##*$Delimeter}"
 Third="${Rhs%+*}"
 One=$(echo "scale=0 ; $First * 1.5" | bc)
 One=${One%.*}
 Two=$(echo "$Second * 1.5" | bc)
 Two=${Two%.*}
 Three=$(echo "$Third * 1.5" | bc)
 Three=${Three%.*}
 Four=$(echo "$Fourth * 1.5" | bc)
 Four=${Four%.*}
 Final=$One"X"$Two"+"$Three"+"$Four
 echo $Final
 convert 1ドル -crop $Final "three.png"
}

Usage like this:

$: convertc2 /Users/dengjiangzhou/Desktop/Simulator\ Screen\ Shot\ -\ iPhone\ 8\ -\ 2019年02月20日\ at\ 14.39.02.png 300X300+0+0

convertc2 /Users/dengjiangzhou/Desktop/Simulator\ Screen\ Shot\ -\ iPhone\ 8\ -\ 2019年02月20日\ at\ 14.39.02.png 300X300+0+0 

$: converto3 /Users/dengjiangzhou/Desktop/Simulator\ Screen\ Shot\ -\ iPhone\ 8\ -\ 2019年02月20日\ at\ 14.39.02.png 300X300+0+0

converto3 /Users/dengjiangzhou/Desktop/Simulator\ Screen\ Shot\ -\ iPhone\ 8\ -\ 2019年02月20日\ at\ 14.39.02.png 300X300+0+0 

I need the image size of @2X and @3X. So the function converto3 use convertc2 's size and transform to its size.

Delimeter="placeHolder"
 
if [[ 2ドル == *"x"* ]]; then
 Delimeter="x"
else
 Delimeter="X"
fi

I really care about how to improve the above code. The "x" , I may type "X" or "x".

how to use this "${2%$Delimeter*}" insensitive?

And the calculation code in converto3() is very ugly.

I use ImageMagick to crop image, encapsulate the related code to functions.

Here is the code:

convertc2(){
 convert 1ドル -crop 2ドル "two.png"
}
converto3(){
 Delimeter="placeHolder"
 if [[ 2ドル == *"x"* ]]; then
 Delimeter="x"
 else
 Delimeter="X"
 fi
 First="${2%$Delimeter*}"
 Fourth="${2##*+}"
 Lhs="${2%%+*}"
 Rhs="${2#"$Lhs+"}"
 Second="${Lhs##*$Delimeter}"
 Third="${Rhs%+*}"
 One=$(echo "scale=0 ; $First * 1.5" | bc)
 One=${One%.*}
 Two=$(echo "$Second * 1.5" | bc)
 Two=${Two%.*}
 Three=$(echo "$Third * 1.5" | bc)
 Three=${Three%.*}
 Four=$(echo "$Fourth * 1.5" | bc)
 Four=${Four%.*}
 Final=$One"X"$Two"+"$Three"+"$Four
 echo $Final
 convert 1ドル -crop $Final "three.png"
}

Usage like this:

$: convertc2 /Users/dengjiangzhou/Desktop/Simulator\ Screen\ Shot\ -\ iPhone\ 8\ -\ 2019年02月20日\ at\ 14.39.02.png 300X300+0+0

$: converto3 /Users/dengjiangzhou/Desktop/Simulator\ Screen\ Shot\ -\ iPhone\ 8\ -\ 2019年02月20日\ at\ 14.39.02.png 300X300+0+0

I need the image size of @2X and @3X. So the function converto3 use convertc2 's size and transform to its size.

Delimeter="placeHolder"
 
if [[ 2ドル == *"x"* ]]; then
 Delimeter="x"
else
 Delimeter="X"
fi

I really care about how to improve the above code. The "x" , I may type "X" or "x".

how to use this "${2%$Delimeter*}" insensitive?

And the calculation code in converto3() is very ugly.

I use ImageMagick to crop image, encapsulate the related code to functions.

Here is the code:

convertc2(){
 convert 1ドル -crop 2ドル "two.png"
}
converto3(){
 Delimeter="placeHolder"
 if [[ 2ドル == *"x"* ]]; then
 Delimeter="x"
 else
 Delimeter="X"
 fi
 First="${2%$Delimeter*}"
 Fourth="${2##*+}"
 Lhs="${2%%+*}"
 Rhs="${2#"$Lhs+"}"
 Second="${Lhs##*$Delimeter}"
 Third="${Rhs%+*}"
 One=$(echo "scale=0 ; $First * 1.5" | bc)
 One=${One%.*}
 Two=$(echo "$Second * 1.5" | bc)
 Two=${Two%.*}
 Three=$(echo "$Third * 1.5" | bc)
 Three=${Three%.*}
 Four=$(echo "$Fourth * 1.5" | bc)
 Four=${Four%.*}
 Final=$One"X"$Two"+"$Three"+"$Four
 echo $Final
 convert 1ドル -crop $Final "three.png"
}

Usage like this:

convertc2 /Users/dengjiangzhou/Desktop/Simulator\ Screen\ Shot\ -\ iPhone\ 8\ -\ 2019年02月20日\ at\ 14.39.02.png 300X300+0+0 
converto3 /Users/dengjiangzhou/Desktop/Simulator\ Screen\ Shot\ -\ iPhone\ 8\ -\ 2019年02月20日\ at\ 14.39.02.png 300X300+0+0 

I need the image size of @2X and @3X. So the function converto3 use convertc2 's size and transform to its size.

Delimeter="placeHolder"
 
if [[ 2ドル == *"x"* ]]; then
 Delimeter="x"
else
 Delimeter="X"
fi

I really care about how to improve the above code. The "x" , I may type "X" or "x".

how to use this "${2%$Delimeter*}" insensitive?

And the calculation code in converto3() is very ugly.

Source Link
black_pearl
  • 220
  • 1
  • 10
Loading
lang-bash

AltStyle によって変換されたページ (->オリジナル) /