#!/bin/bash
#
#
#    "iconrb" Tool for rounding icons edges.
#
#    See the file COPYING.GPL.txt, included in this distribution,
#    for details about the copyright.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
#    "iconrb" Copyright (c) by "Fedoramedia team". Is free software,  This
#    works in GNU/Linux, FreeBSD and others, is freed under the terms of the
#    GPL (GNU GENERAL PUBLIC LICENSE). More information can be found in :
#
#    http://www.fedoramedia.cf
#
#    Wednesday september 26 2018
#    _________________________________________________________
#
#    You can support this project by sending a donation to :
#
#    Paypal [http://mklauncher.osdn.io/en/donate.html]
#
#
rb_File="rb-$1"
rb_mask="/tmp/mask256x256.png"
rb_Version="1.0"
rb_Date="Thursday, March 14, 2019"

##### Main

if [ "$1" = "-help" ]; then
   echo ""
   echo "\"iconrb\" Version $rb_Version $rb_Date"
   echo "Tool for rounding icons edges http://www.fedoramedia.cf"
   echo ""
   echo "Command line :"
   echo ""
   echo "iconrb \"Namefile.png\""
   echo ""
   echo ""
   echo "Note"
   echo ""
   echo "iconrb \"Namefile.png\" Create a copy of the file with rounded edges, "
   echo "the file must be in PNG format and to have 256 x 256 pixels. "
   echo "\"iconrb\" requires \"imagemagick\". Installation of \"imagemagick\" :"
   echo ""
   echo "# yum install ImageMagick"
   echo ""
   echo "# dnf install ImageMagick"
   echo ""
   echo "# apt install imagemagick"
   echo ""
   echo "# pkg install ImageMagick"
   echo ""
   echo ""
   echo "Examples"
   echo ""
   echo "iconrb \"Namefile.png\""
   echo ""
   echo "rb-Namefile.png"
   echo ""
   exit 0
fi 

if [ "-f $rb_mask" != "0" ]; then 
   convert -size 256x256 xc:#000000 -strokewidth 1 -fill "#ffffff" -draw "RoundRectangle 0,0 255,255 25,25" $rb_mask

   if [ "$?" != "0" ]; then
      exit 1
   fi  
fi

convert $1 $rb_mask -alpha Off -compose CopyOpacity -composite $rb_File

if [ "$?" != "0" ]; then
   exit 2
fi  
#
#
