Advertisement
metalx1000

ImageMagick FZF Script

Mar 24th, 2020
878
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.89 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2020  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation, either version 3 of the License, or
  9. #(at your option) any later version.
  10.  
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #GNU General Public License for more details.
  15.  
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. ######################################################################
  19.  
  20.  
  21. dir="output"
  22. mkdir -p "$dir"
  23. files="$(ls *.{jpg,png,JPG,JPEG,jpeg,gif} 2>/dev/null)"
  24. functions="grey
  25. sepia
  26. resize
  27. equalize"
  28.  
  29. function main(){
  30.   files="$(echo "$files"|fzf -m --prompt "Please Select Images: " )"
  31.   exit-none "$files"
  32.  
  33.   func="$(echo "$functions"|fzf --prompt "Select Function: " )"
  34.   exit-none "$func"
  35.  
  36.   if [ "$func" = "resize" ];then
  37.     percent
  38.   fi
  39.  
  40.   for img in $files
  41.   do
  42.     ext="$(echo "$img"|cut -d\. -f2)"
  43.     img2="$(echo "$img"|cut -d\. -f1)_$(date +%s).$ext"
  44.     echo "Converting $img to $dir/${img2}"
  45.     $func "$img" "$dir/${img2}"
  46.   done
  47. }
  48.  
  49. function percent(){
  50.   perc="$(seq 1 200|fzf --prompt "Select a Percent")%"
  51. }
  52.  
  53. #exit if none selected
  54. function exit-none(){
  55.   if [ "$1" = "" ];then
  56.     echo "None Selected"
  57.     exit
  58.   fi
  59. }
  60.  
  61. #Image Functions
  62. function equalize(){
  63.   convert "$1" -equalize "$2"
  64. }
  65.  
  66. function grey(){
  67.   convert "$1" -colorspace Gray "$2"
  68. }
  69.  
  70. function sepia(){
  71.   convert "$1" -sepia-tone '80%' "$2"
  72. }
  73.  
  74. function resize(){
  75.   convert "$1" -resize "${perc}" "$2"
  76. }
  77.  
  78. main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement