#!/bin/bash
# =============================================
# https://bandithijo.github.io/blog/memodifikasi-screenshot-dari-flameshot-dengan-imagemagick
# https://github.com/berrabe/awesome-flameshot
# =============================================
#_SCREENSHOT_DIR_=$HOME
_SCREENSHOT_DIR_=/home/sunu/FlameshotBorder/savedPIC
#_LOG_FILE_="$_SCREENSHOT_DIR_/awesome-flameshot.log"
_LOG_FILE_="/home/sunu/FlameshotBorder/awesome-flameshot.log"
_FG_COLOR_='#000000'
#_BG_COLOR_='#ffffff'
_BG_COLOR_="none"
_BG_SIZE_=1
# Border Size Applied when value greater than or equal 3
_BORDER_SIZE_=3
_SHADOW_SIZE_='00x00+00+00'
_ROUNDED_CORNER_=1
#_AUTHOR_POST_=( 'South' '+0+26' )
#_AUTHOR_NAME_=" $USER $(date '+ %d.%m.%y %H:%M')"
#_AUTHOR_COLOR_='#000000'
_AUTHOR_POST_=( 'South' '+0+26' )
_AUTHOR_NAME_=" $USER $(date '+ %d.%m.%y %H:%M')"
_AUTHOR_COLOR_='#000000'
# Get Lists Font With "convert -list font | grep -iE 'font:.*' | nl"
_FONT_SIZE_=9
_FONT_='Helvetica'
# =============================================
# List of Colors
Light_Red="\033[1;31m"
Light_Green="\033[1;32m"
Yellow="\033[1;33m"
Light_Blue="\033[1;34m"
Light_Purple="\033[1;35m"
Light_Cyan="\033[1;36m"
NoColor="\033[0m"
trap ctrl_c INT
function ctrl_c() {
echo -ne " -- Exiting -- "
}
function check() {
if [[ $? -eq 0 && ${PIPESTATUS[0]} -eq 0 ]]; then
echo -e "${Light_Green} [ Success ] ${NoColor}"
else
echo -e "${Light_Red} [ Failed ] ${NoColor}"
echo -e "\n\n${Light_Cyan} [+] SUMMARY |${Light_Red} FAILED ${NoColor}"
_end_job_=$(date +%s)
summary $_start_job_ $_end_job_ 'failed' && notify-send -u critical -t 3000 "[ ERROR ] Awesome-Flameshot : $_LOG_FILE_" >> $_LOG_FILE_ 2>&1
exit 1
fi
}
function get_latest_img() {
_LATEST_IMAGE_=$(/bin/ls -th $_SCREENSHOT_DIR_ | grep -vE '.edited.png$' | grep -E '.png$' | head -n 1)
if [[ $( echo "$_LATEST_IMAGE_" | wc -w ) -eq 0 ]]; then
echo -e "${Light_Purple} [ No New Image Detected ] ${NoColor}"
exit 1
else
echo -e "${Light_Green} [ Success ] ${Yellow} ($_LATEST_IMAGE_) ${NoColor}"
_LATEST_IMAGE_="$_SCREENSHOT_DIR_/$_LATEST_IMAGE_"
fi
}
function convert() {
_target_file_=$( echo "$_LATEST_IMAGE_" | sed 's/.png/.edited.png/g' )
if [[ $_BORDER_SIZE_ -ge 3 ]]; then
printf "%-50s" "**|--[+]*Generate*Image*Info*" | sed 's/ /./g' | sed 's/*/ /g'
magick convert "$_LATEST_IMAGE_" \
-format 'roundrectangle 1,1 %[fx:w+4],%[fx:h+4] '"$_ROUNDED_CORNER_"','"$_ROUNDED_CORNER_"''\
info: > $_SCREENSHOT_DIR_/_rounded_.mvg
check
printf "%-50s" "**|--[+]*Generate*Rounded*Masking*" | sed 's/ /./g' | sed 's/*/ /g'
magick convert "$_LATEST_IMAGE_" -border $_BORDER_SIZE_ -alpha transparent \
-background none -fill white -stroke none -strokewidth 0 \
-draw "@"$_SCREENSHOT_DIR_"/_rounded_.mvg" $_SCREENSHOT_DIR_/_rounded_mask_.png >> $_LOG_FILE_ 2>&1
check
printf "%-50s" "**|--[+]*Generate*Rounded*Overlay*" | sed 's/ /./g' | sed 's/*/ /g'
magick convert "$_LATEST_IMAGE_" -border $_BORDER_SIZE_ -alpha transparent \
-background none -fill none -stroke $_FG_COLOR_ -strokewidth $_BORDER_SIZE_ \
-draw "@"$_SCREENSHOT_DIR_"/_rounded_.mvg" $_SCREENSHOT_DIR_/_rounded_overlay_.png >> $_LOG_FILE_ 2>&1
check
printf "%-50s" "**|--[+]*Set*Rounded*Corner*&*Border*Color*" | sed 's/ /./g' | sed 's/*/ /g'
magick convert "$_LATEST_IMAGE_" -alpha set -bordercolor none -border $_BORDER_SIZE_ \
$_SCREENSHOT_DIR_/_rounded_mask_.png -compose DstIn -composite \
$_SCREENSHOT_DIR_/_rounded_overlay_.png -compose Over -composite \
"$_target_file_" >> $_LOG_FILE_ 2>&1 && \
rm -f $_SCREENSHOT_DIR_/_rounded_*
check
else
printf "%-50s" "**|--[+]*Set*Rounded*Corner*" | sed 's/ /./g' | sed 's/*/ /g'
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' \
\( +clone -flip \) -compose Multiply -composite \
\( +clone -flop \) -compose Multiply -composite \
\) -alpha off -compose CopyOpacity -composite -compose over "$_target_file_" >> $_LOG_FILE_ 2>&1
check
fi
printf "%-50s" "**|--[+]*Set*Image*Shadow*" | sed 's/ /./g' | sed 's/*/ /g'
magick convert "$_target_file_" \( +clone -background black -shadow $_SHADOW_SIZE_ \) +swap -background none -layers merge +repage "$_target_file_" >> $_LOG_FILE_ 2>&1 \
&& magick convert "$_target_file_" -bordercolor $_BG_COLOR_ -border $_BG_SIZE_ "$_target_file_" >> $_LOG_FILE_ 2>&1
check
# printf "%-50s" "**|--[+]*Set*Image*Author*" | sed 's/ /./g' | sed 's/*/ /g'
# 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_" \
# >> $_LOG_FILE_ 2>&1 && magick convert "$_target_file_" -gravity South -chop 0x$(( $_BG_SIZE_ / 2 )) "$_target_file_" >> $_LOG_FILE_ 2>&1
# check
printf "%-50s" "**|--[+]*Add*Top*/*North*BG*" | sed 's/ /./g' | sed 's/*/ /g'
magick convert "$_target_file_" -gravity North -background $_BG_COLOR_ -splice 0x$(( $_BG_SIZE_ / 2 )) "$_target_file_" >> $_LOG_FILE_ 2>&1
check
printf "%-50s" "**|--[+]*Set*sRGB*Image*Profile*" | sed 's/ /./g' | sed 's/*/ /g'
magick convert "$_target_file_" -profile /usr/share/color/icc/colord/sRGB.icc "$_target_file_" >> $_LOG_FILE_ 2>&1
check
}
function summary() {
_runtime_job_=$(($2-$1))
hours=$((_runtime_job_ / 3600)); minutes=$(( (_runtime_job_ % 3600) / 60 )); seconds=$(( (_runtime_job_ % 3600) % 60 ))
printf "%s %s\n" " |--[+] Elapsed Time : " "$hours : $minutes : $seconds"
if [[ $3 != "failed" ]]; then
printf "%s %s" " |--[+] Output File : " "$_target_file_"
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
if [[ $? -eq 0 ]]; then
echo -e "${Light_Green} (Copied to Clipboard) ${NoColor}"
else
echo -e "${Light_Red} (Copy to Clipboard Failed) ${NoColor}"
fi
fi
_error_count_=$(cat $_LOG_FILE_ 2> /dev/null | wc -l)
if [[ $_error_count_ -ge 1 ]]; then
printf "%s ${Light_Red}%s --> $_LOG_FILE_ ${NoColor}\n\n" " |--[+] Error Count : " $_error_count_
else
printf "%s ${Light_Green}%s --> $_LOG_FILE_ ${NoColor}\n\n" " |--[+] Error Count : " $_error_count_
fi
}
function main() {
echo -e "\n\n\t\t\t${Light_Blue} AWESOME FLAMESHOT ${NoColor}\n"
rm -f $_LOG_FILE_
_start_job_=$(date +%s)
echo -e "\n\n${Light_Cyan} [+] SCRENSHOTING ${NoColor}"
printf "%-50s" "**|--[+]*Starting*Flameshot*" | sed 's/ /./g' | sed 's/*/ /g'
flameshot gui --raw --delay 4000 > /dev/null 2>&1
check
printf "%-50s" "**|--[+]*Checking*Latest*Image*" | sed 's/ /./g' | sed 's/*/ /g'
get_latest_img
echo -e "\n\n${Light_Cyan} [+] CONVERTING ${NoColor}"
convert
echo -e "\n\n${Light_Cyan} [+] SUMMARY ${NoColor}"
_end_job_=$(date +%s)
summary $_start_job_ $_end_job_
}
clear
main
Comments