Advertisement
sunu

Flameshot screenshot border

Jul 19th, 2021
1,084
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # =============================================
  4.  
  5. # https://bandithijo.github.io/blog/memodifikasi-screenshot-dari-flameshot-dengan-imagemagick
  6.  
  7. # https://github.com/berrabe/awesome-flameshot
  8.  
  9. # =============================================
  10.  
  11.  
  12. #_SCREENSHOT_DIR_=$HOME
  13. _SCREENSHOT_DIR_=/home/sunu/FlameshotBorder/savedPIC
  14. #_LOG_FILE_="$_SCREENSHOT_DIR_/awesome-flameshot.log"
  15. _LOG_FILE_="/home/sunu/FlameshotBorder/awesome-flameshot.log"
  16.  
  17. _FG_COLOR_='#000000'
  18. #_BG_COLOR_='#ffffff'
  19. _BG_COLOR_="none"
  20. _BG_SIZE_=1
  21.  
  22. # Border Size Applied when value greater than or equal 3
  23. _BORDER_SIZE_=3
  24. _SHADOW_SIZE_='00x00+00+00'
  25. _ROUNDED_CORNER_=1
  26.  
  27. #_AUTHOR_POST_=( 'South' '+0+26' )
  28. #_AUTHOR_NAME_="  $USER  $(date '+    %d.%m.%y     %H:%M')"
  29. #_AUTHOR_COLOR_='#000000'
  30.  
  31. _AUTHOR_POST_=( 'South' '+0+26' )
  32. _AUTHOR_NAME_="  $USER  $(date '+    %d.%m.%y     %H:%M')"
  33. _AUTHOR_COLOR_='#000000'
  34.  
  35. # Get Lists Font With "convert -list font | grep -iE 'font:.*' | nl"
  36. _FONT_SIZE_=9
  37. _FONT_='Helvetica'
  38.  
  39. # =============================================
  40.  
  41. # List of Colors
  42. Light_Red="\033[1;31m"
  43. Light_Green="\033[1;32m"
  44. Yellow="\033[1;33m"
  45. Light_Blue="\033[1;34m"
  46. Light_Purple="\033[1;35m"
  47. Light_Cyan="\033[1;36m"
  48. NoColor="\033[0m"
  49.  
  50.  
  51. trap ctrl_c INT
  52.  
  53. function ctrl_c() {
  54.  
  55.     echo -ne "  -- Exiting --  "
  56. }
  57.  
  58. function check() {
  59.  
  60.     if [[ $? -eq 0 && ${PIPESTATUS[0]} -eq 0 ]]; then
  61.         echo -e "${Light_Green} [ Success ] ${NoColor}"
  62.     else
  63.         echo -e "${Light_Red} [ Failed ] ${NoColor}"
  64.  
  65.         echo -e "\n\n${Light_Cyan} [+] SUMMARY |${Light_Red} FAILED ${NoColor}"
  66.         _end_job_=$(date +%s)
  67.         summary $_start_job_ $_end_job_ 'failed' && notify-send -u critical -t 3000 "[ ERROR ]  Awesome-Flameshot : $_LOG_FILE_" >> $_LOG_FILE_ 2>&1
  68.         exit 1
  69.     fi
  70. }
  71.  
  72. function get_latest_img() {
  73.  
  74.     _LATEST_IMAGE_=$(/bin/ls -th $_SCREENSHOT_DIR_ | grep -vE '.edited.png$' | grep -E '.png$' | head -n 1)
  75.  
  76.     if [[ $( echo "$_LATEST_IMAGE_" | wc -w ) -eq 0 ]]; then
  77.         echo -e "${Light_Purple} [ No New Image Detected ] ${NoColor}"
  78.         exit 1
  79.     else
  80.         echo -e "${Light_Green} [ Success ] ${Yellow} ($_LATEST_IMAGE_) ${NoColor}"
  81.         _LATEST_IMAGE_="$_SCREENSHOT_DIR_/$_LATEST_IMAGE_"
  82.     fi
  83. }
  84.  
  85. function convert() {
  86.  
  87.     _target_file_=$( echo "$_LATEST_IMAGE_" | sed 's/.png/.edited.png/g'  )
  88.  
  89.     if [[ $_BORDER_SIZE_ -ge 3 ]]; then
  90.         printf "%-50s" "**|--[+]*Generate*Image*Info*" | sed 's/ /./g' | sed 's/*/ /g'
  91.         magick convert "$_LATEST_IMAGE_" \
  92.             -format 'roundrectangle 1,1 %[fx:w+4],%[fx:h+4] '"$_ROUNDED_CORNER_"','"$_ROUNDED_CORNER_"''\
  93.             info: > $_SCREENSHOT_DIR_/_rounded_.mvg
  94.         check
  95.  
  96.         printf "%-50s" "**|--[+]*Generate*Rounded*Masking*" | sed 's/ /./g' | sed 's/*/ /g'
  97.         magick convert "$_LATEST_IMAGE_" -border $_BORDER_SIZE_ -alpha transparent \
  98.             -background none -fill white -stroke none -strokewidth 0 \
  99.             -draw "@"$_SCREENSHOT_DIR_"/_rounded_.mvg" $_SCREENSHOT_DIR_/_rounded_mask_.png >> $_LOG_FILE_ 2>&1
  100.         check
  101.  
  102.         printf "%-50s" "**|--[+]*Generate*Rounded*Overlay*" | sed 's/ /./g' | sed 's/*/ /g'
  103.         magick convert "$_LATEST_IMAGE_" -border $_BORDER_SIZE_ -alpha transparent \
  104.             -background none -fill none -stroke $_FG_COLOR_ -strokewidth $_BORDER_SIZE_ \
  105.             -draw "@"$_SCREENSHOT_DIR_"/_rounded_.mvg" $_SCREENSHOT_DIR_/_rounded_overlay_.png >> $_LOG_FILE_ 2>&1
  106.         check
  107.  
  108.         printf "%-50s" "**|--[+]*Set*Rounded*Corner*&*Border*Color*" | sed 's/ /./g' | sed 's/*/ /g'
  109.         magick convert "$_LATEST_IMAGE_" -alpha set -bordercolor none -border $_BORDER_SIZE_  \
  110.             $_SCREENSHOT_DIR_/_rounded_mask_.png -compose DstIn -composite \
  111.             $_SCREENSHOT_DIR_/_rounded_overlay_.png -compose Over -composite \
  112.             "$_target_file_" >> $_LOG_FILE_ 2>&1 && \
  113.         rm -f $_SCREENSHOT_DIR_/_rounded_*
  114.         check
  115.     else
  116.         printf "%-50s" "**|--[+]*Set*Rounded*Corner*" | sed 's/ /./g' | sed 's/*/ /g'
  117.         magick convert "$_LATEST_IMAGE_" \( +clone  -alpha extract -draw 'fill black polygon 0,0 0,'"$_ROUNDED_CORNER_"' '"$_ROUNDED_CORNER_"',0 fill white circle '"$_ROUNDED_CORNER_"','"$_ROUNDED_CORNER_"' '"$_ROUNDED_CORNER_"',0' \
  118.         \( +clone -flip \) -compose Multiply -composite \
  119.         \( +clone -flop \) -compose Multiply -composite \
  120.         \) -alpha off -compose CopyOpacity -composite -compose over "$_target_file_" >> $_LOG_FILE_ 2>&1
  121.         check
  122.     fi
  123.  
  124.     printf "%-50s" "**|--[+]*Set*Image*Shadow*" | sed 's/ /./g' | sed 's/*/ /g'
  125.     magick convert "$_target_file_" \( +clone -background black -shadow $_SHADOW_SIZE_ \) +swap -background none -layers merge +repage "$_target_file_" >> $_LOG_FILE_ 2>&1 \
  126.     && magick convert "$_target_file_" -bordercolor $_BG_COLOR_ -border $_BG_SIZE_ "$_target_file_" >> $_LOG_FILE_ 2>&1
  127.     check
  128.  
  129. #    printf "%-50s" "**|--[+]*Set*Image*Author*" | sed 's/ /./g' | sed 's/*/ /g'
  130. #    echo -en "  $_AUTHOR_NAME_  " | magick convert "$_target_file_" -gravity ${_AUTHOR_POST_[0]} -pointsize $_FONT_SIZE_ -fill $_AUTHOR_COLOR_ -undercolor $_FG_COLOR_ -font $_FONT_ -annotate ${_AUTHOR_POST_[1]} @- "$_target_file_" \
  131. #    >> $_LOG_FILE_ 2>&1 && magick convert "$_target_file_" -gravity South -chop 0x$(( $_BG_SIZE_ / 2 )) "$_target_file_" >> $_LOG_FILE_ 2>&1
  132. #    check
  133.  
  134.     printf "%-50s" "**|--[+]*Add*Top*/*North*BG*" | sed 's/ /./g' | sed 's/*/ /g'
  135.     magick convert "$_target_file_" -gravity North -background $_BG_COLOR_ -splice 0x$(( $_BG_SIZE_ / 2 )) "$_target_file_" >> $_LOG_FILE_ 2>&1
  136.     check
  137.  
  138.     printf "%-50s" "**|--[+]*Set*sRGB*Image*Profile*" | sed 's/ /./g' | sed 's/*/ /g'
  139.     magick convert "$_target_file_" -profile /usr/share/color/icc/colord/sRGB.icc "$_target_file_" >> $_LOG_FILE_ 2>&1
  140.     check
  141. }
  142.  
  143. function summary() {
  144.  
  145.     _runtime_job_=$(($2-$1))
  146.     hours=$((_runtime_job_ / 3600)); minutes=$(( (_runtime_job_ % 3600) / 60 )); seconds=$(( (_runtime_job_ % 3600) % 60 ))
  147.  
  148.     printf "%s %s\n" "  |--[+] Elapsed Time : " "$hours : $minutes : $seconds"
  149.  
  150.     if [[ $3 != "failed" ]]; then
  151.         printf "%s %s" "  |--[+] Output File  : " "$_target_file_"
  152.  
  153.         xclip -selection clipboard -t image/png -i $_target_file_ >> $_LOG_FILE_ 2>&1 && notify-send -u normal -t 3000 "Awesome-Flameshot: $_target_file_ Copied" >> $_LOG_FILE_ 2>&1
  154.         if [[ $? -eq 0 ]]; then
  155.             echo -e "${Light_Green} (Copied to Clipboard) ${NoColor}"
  156.         else
  157.             echo -e "${Light_Red} (Copy to Clipboard Failed) ${NoColor}"
  158.         fi
  159.     fi
  160.  
  161.     _error_count_=$(cat $_LOG_FILE_ 2> /dev/null | wc -l)
  162.     if [[ $_error_count_ -ge 1 ]]; then
  163.         printf "%s ${Light_Red}%s  -->  $_LOG_FILE_ ${NoColor}\n\n" "  |--[+] Error Count  : " $_error_count_
  164.     else
  165.         printf "%s ${Light_Green}%s  -->  $_LOG_FILE_ ${NoColor}\n\n" "  |--[+] Error Count  : " $_error_count_
  166.     fi
  167. }
  168.  
  169. function main() {
  170.  
  171.     echo -e "\n\n\t\t\t${Light_Blue} AWESOME FLAMESHOT ${NoColor}\n"
  172.     rm -f $_LOG_FILE_
  173.     _start_job_=$(date +%s)
  174.     echo -e "\n\n${Light_Cyan} [+] SCRENSHOTING ${NoColor}"
  175.  
  176.     printf "%-50s" "**|--[+]*Starting*Flameshot*" | sed 's/ /./g' | sed 's/*/ /g'
  177.     flameshot gui --raw --delay 4000 > /dev/null 2>&1
  178.     check
  179.  
  180.     printf "%-50s" "**|--[+]*Checking*Latest*Image*" | sed 's/ /./g' | sed 's/*/ /g'
  181.     get_latest_img
  182.  
  183.     echo -e "\n\n${Light_Cyan} [+] CONVERTING ${NoColor}"
  184.     convert
  185.  
  186.     echo -e "\n\n${Light_Cyan} [+] SUMMARY ${NoColor}"
  187.     _end_job_=$(date +%s)
  188.     summary $_start_job_ $_end_job_
  189. }
  190.  
  191. clear
  192. main
Advertisement
RAW Paste Data Copied
Advertisement