moved everything under content.
[danix.xyz.git] / articles / gify-back-to-bash-scripting.md
diff --git a/articles/gify-back-to-bash-scripting.md b/articles/gify-back-to-bash-scripting.md
deleted file mode 100644 (file)
index 6737a63..0000000
+++ /dev/null
@@ -1,245 +0,0 @@
----
-title: gify.sh – back to bash scripting
-author: Danilo M.
-type: post
-date: 2016-01-25T12:41:06+00:00
-featured_image: /uploads/2016/01/G0092546.jpg
-categories:
-  - code
-  - diy
-  - fotografia
-tags:
-  - bash
-  - convert
-  - gif
-  - imagemagik
-  - mogrify
-  - script
-
----
-<div class="wp-block-image size-full wp-image-3645">
-  <figure class="aligncenter"><img loading="lazy" width="900" height="675" src="https://danix.xyz/wp-content/uploads/2016/01/piscaturi.gif" alt="" class="wp-image-3645" /><figcaption>gif image created using gify.sh</figcaption></figure>
-</div>
-
-Today I&#8217;ll present you a useful script that will help you create amazing gifs from your still photos using a couple tools from the <a href="https://www.imagemagick.org" target="_blank" rel="noopener noreferrer">IMAGEMAGIK</a> suite, so without further ado, here it is, straight from github&#8217;s gists.
-
-<div class="wp-block-buttons aligncenter">
-  <div class="wp-block-button">
-    <a class="wp-block-button__link" href="" target="_blank" rel="noreferrer noopener">download in zip format</a>
-  </div>
-</div>
-
-what the code does is quite simple, it takes a few arguments and helps you resize your images&nbsp;while keeping the original proportions. Put the code in your path and let&#8217;s put it to work.
-
-<!--more-->
-
-For this example we&#8217;ll pretend you have a bunch of jpg pictures, maybe something you shot while travelling france,&nbsp;put&nbsp;them&nbsp;in a folder and run the script like this:
-
-<pre class="wp-block-code language-bash"><code>gify.sh --resize 900 jpg</code></pre>
-
-depending on the amount of images it may take a while, and when it&#8217;s done you&#8217;ll have all of your jpg resized to 900px wide and with proportional height.
-
-now it&#8217;s time to render all of your jpg into one animated gif so, while in the same directory, run the script like this:
-
-<pre class="wp-block-code language-bash"><code>gify.sh --gif 10 jpg paris</code></pre>
-
-the parameters now are a bit different, first we tell the script that we want to create a gif with the `--gif` option, then we tell the interval between every frame, that number is expressed in 100th of a second, so now we are telling the gif to change frame every 10/100 of second, the following parameter is the extension of the images we&#8217;ll be using, in our example is jpg (it&#8217;s case sensitive, so make sure all the images you want to use have the same extension), and finally we set the name of the gif, without the extension, the script will provide it for us.
-
-The gif you see at the beginning of the article was created with this script.
-
-I made this script mostly for fun and personal use, so it&#8217;s absolutely not idiot proof, can be improved but for me it works just fine. If you want to modify it, feel free to fork it on github or just download it and do whatever you like with it, and if you want to share it with me, use the comment form below.
-
-I&#8217;ll leave you with a copy of the script here in case you want to have a look at it before downloading.  
-Enjoy!
-
-{{< highlight bash "linenos=true" >}}#! /bin/bash
-
-# Author:       Danilo 'danix' Macri
-# Author URI:   https://danix.xyz
-# Script URI:   https://danix.xyz/?p=3545
-# License:      GPL2
-# License URI:  https://www.gnu.org/licenses/gpl-2.0.html
-
-#--------------------------------------------------------------------------------#
-#                                                                                #
-#             GIFY.SH - CREATE ANIMATED GIFS OUT OF A BUNCH OF IMAGES            #
-#                                                                                #
-# Use this script to create animated looping gifs from a bunch of images. You    #
-# just need to arrange all the images you want to use inside a folder and then   #
-# launch this script with a few options and you'll have your gif within seconds. #
-#                                                                                #
-# This script uses mogrify and convert from the IMAGEMAGIK suite to deliver the  #
-# gifs. This script can proportionally resize your images to help you create a   #
-# lighter file.                                                                  #
-#                                                                                #
-#--------------------------------------------------------------------------------#
-
-# ERROR & EXIT STATUSES
-SHOWHELP=61
-USERABORTED=62
-
-E_INTERROR=71
-E_NOOPTS=72
-E_NOARGS=73
-E_FILEXISTS=74
-E_NOIMAGES=75
-E_UNKNOWNOPT=76
-
-# TOOLS
-PWD=$(pwd)
-MOGRIFY=$(which mogrify)
-CONVERT=$(which convert)
-
-# we need mogrify and convert from the imagemagik toolset for this script to work
-if &#91;&#91; ! -x $MOGRIFY || ! -x $CONVERT ]]; then
-    showerror missingdeps
-    exit $E_MISSINGDEPS
-fi
-
-
-# showhelp
-showhelp ()
-{
-case $1 in
-    resize )
-        echo "USAGE: $(basename $0) -r | --resize &#91;width] &#91;extension]"
-        ;;
-    gif )
-        echo "USAGE: $(basename $0) -g | --gif &#91;delay] &#91;extension] &#91;output file name]"
-        ;;
-    * )
-                #|----------------------- TEXT MAX WIDTH - 80 CHARS ----------------------------|
-        echo -e "$(basename $0) - create animated gifs from images inside current directory"
-        echo -e "USAGE: $(basename $0) &lt;option> &#91;arguments]"
-        echo -e "\twhere &lt;option> is one between:";echo
-        echo -e "\t-r | --resize &#91;width] &#91;extension]"
-        echo -e "\t\tresizes all the images matching the extension in the current folder to"
-        echo -e "\t\tthe width specified as argument.";echo
-        echo -e "\tg | --gif &#91;delay] &#91;extension] &#91;output file name]"
-        echo -e "\t\tcreates the gif file using all the images in the current folder."
-        echo
-        echo -e "EXAMPLES:"
-        echo -e "$(basename $0) --resize 900 jpg"
-        echo -e "\twill resize all jpg images in the folder to 900px wide and mantain the"
-        echo -e "\taspect ratio of the original images"
-        echo
-        echo -e "$(basename $0) --gif 8 jpg france"
-        echo -e "\twill create a looping gif named france.gif using all the jpg files found"
-        echo -e "\tin the current folder and passing a tick delay of 8 between frames".
-        echo
-        ;;
-esac
-}
-
-# showerror
-showerror ()
-{
-    if &#91; -z $1 ];then
-        echo "INTERNAL ERROR - ABORTING"; echo
-        exit $E_INTERROR
-    fi
-    case $1 in
-        unknownopt)
-            echo "unknown option. Exiting."; echo
-        ;;
-        noopts)
-            echo "you didn't specify any options for the script to run. Exiting."; echo
-        ;;
-        noargs)
-            echo "you didn't specify any arguments for this option. Exiting."; echo
-        ;;
-        filexists)
-            echo "the file you want to write already exists. Exiting."; echo
-        ;;
-        noimages)
-            echo "at least two files must exist within $PWD with the"
-            echo "specified extension. Exiting"; echo
-        ;;
-        missingdeps)
-            echo "$(basename $0) requires both mogrify and convert from"
-            echo "the imagemagik tool suite. Install imagemagik using your"
-            echo "favourite package manager and then run this script again. Exiting."; echo
-    esac
-}
-
-##### MAIN #####
-if &#91; $# -eq 0 ];then
-    showerror noopts
-    showhelp
-    exit $E_NOOPTS
-else
-
-    while &#91; $# -gt 0 ];do
-        case $1 in
-            -h|--help)
-                showhelp
-                exit $SHOWHELP
-            ;;
-            -r|--resize)
-                WIDTH=$2
-                EXT=$3
-                shift
-                if &#91;&#91; -z $WIDTH || -z $EXT ]];then
-                    showhelp resize
-                    showerror noargs
-                    exit $E_NOARGS
-                fi
-                IMAGES="$(ls -1 *.$EXT 2>/dev/null | wc -l)"
-                if &#91;&#91; $IMAGES == 0 ]]; then
-                    showerror noimages
-                    exit $E_NOIMAGES
-                fi
-                clear
-                COUNT="$(ls -1 *.$EXT 2>/dev/null | wc -l)"
-                echo "you're going to resize all $COUNT .$EXT images inside $PWD at a fixed width of ${WIDTH}px"
-                read -p "do you wish to continue? &#91;y/n] " -n 1 -r; echo
-                if &#91;&#91; ! $REPLY =~ ^&#91;Yy]$ ]]
-                then
-                    exit $USERABORTED
-                else
-                $MOGRIFY -resize $WIDTH *.$EXT
-                exit 0
-                fi
-            ;;
-            -g|--gif)
-                DELAY=$2
-                EXT=$3
-                OUTPUT=$4
-                shift
-                if &#91;&#91; -z $DELAY || -z $EXT || -z $OUTPUT ]];then
-                    showhelp gif
-                    showerror noargs
-                    exit $E_NOARGS
-                elif &#91;&#91; -f ${OUTPUT}.gif ]]; then
-                    showerror filexists
-                    exit $E_FILEXISTS
-                fi
-                IMAGES="$(ls -1 *.$EXT 2>/dev/null | wc -l)"
-                if &#91;&#91; $IMAGES == 0 ]]; then
-                    showerror noimages
-                    exit $E_NOIMAGES
-                fi
-                clear
-                COUNT="$(ls -1 *.$EXT 2>/dev/null | wc -l)"
-                echo "you're going to create a looping gif named ${OUTPUT}.gif"
-                echo "out of all the $COUNT $EXT files inside $PWD with a tick"
-                echo "delay of $DELAY/100 of a second"; echo
-                read -p "do you wish to continue? &#91;y/n] " -n 1 -r; echo
-                if &#91;&#91; ! $REPLY =~ ^&#91;Yy]$ ]]
-                then
-                    exit $USERABORTED
-                else
-                    $CONVERT -delay $DELAY *.$EXT -loop 0 ${OUTPUT}.gif
-                    exit 0
-                fi
-            ;;
-            *)
-                showerror unknownopt
-                showhelp
-                exit $E_UNKNOWNOPT
-        esac
-        shift
-    done
-fi
-
-{{< /highlight >}}
\ No newline at end of file