Browse Source

Image anonymizer

netico 2 years ago
parent
commit
7ce251edb3

+ 34 - 0
Graphics/image-anonymizer/README.md

@@ -0,0 +1,34 @@
+# Image anonymizer
+
+**Image anonymizer** is a frontend program for some tools that work with images.
+
+The program makes a **PNG** copy of the original image; the copy is optimized and **all metadata is removed**.
+
+## Screenshots
+
+![001](screenshot-001.png)
+![002](screenshot-002.png)
+![003](screenshot-003.png)
+![004](screenshot-004.png)
+
+## Install
+
+### Requirements
+
+* **[GNU bash](https://www.gnu.org/software/bash/)** is the **GNU Project**'s shell—the **Bourne Again SHell**.
+* **[Zenity](https://help.gnome.org/users/zenity/)** is a rewrite of **gdialog**, the **GNOME** port of dialog which allows you to display dialog boxes from the commandline and shell scripts.
+* **[ImageMagick](https://imagemagick.org/)** is a suite of programs for creating, editing, compositing or converting digital images. It can read and write images in a variety of formats.
+* **[Exiftool](https://www.exiftool.org/)** is a platform-independent **Perl library** plus a command-line application for reading, writing and editing meta information in a wide variety of files.
+* **[OptiPNG](http://optipng.sourceforge.net/)** is a **PNG optimizer** that recompresses image files to a smaller size, without losing any information.
+
+### Get the code
+
+You can use **git**.
+
+    git clone https://git.lattuga.net/netico/code-library.git
+
+and then look for the script **image-anonymizer.sh**.
+
+## Usage
+
+  	./image-anonymizer.sh &

+ 2 - 0
Graphics/image-anonymizer/gui/bottom.tpl

@@ -0,0 +1,2 @@
+  </body>
+</html>

+ 12 - 0
Graphics/image-anonymizer/gui/start.tpl

@@ -0,0 +1,12 @@
+<h1>Image anonymizer</h1>
+<h4>Version {VERSION}</h4>
+<p>License GPLv3+: <a href='https://www.gnu.org/licenses/gpl-3.0.html'>GNU GPL version 3 or later</a>
+<br>This is free software; you are free to change and redistribute it.</p>
+<p>
+  Powered by<br>
+  <b><a href="https://www.gnu.org/software/bash/">GNU bash</a></b>: {BASH}<br>
+  <b><a href="https://help.gnome.org/users/zenity/">Zenity</a></b>: {DIALOG}<br>
+  <b><a href="https://imagemagick.org/">ImageMagick</a></b>: {IM}<br>
+  <b><a href="https://www.exiftool.org/">Exiftool</a></b>: {EXIFTOOL} <br>
+  <b><a href="http://optipng.sourceforge.net/">OptiPNG</a></b>: {OPTIPNG}<br>
+</p>

+ 18 - 0
Graphics/image-anonymizer/gui/top.tpl

@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html lang="en">
+  <head>
+    <meta charset="utf-8">
+    <title>Image anonymizer</title>
+    <style>
+    body {
+      background-image: linear-gradient(to right, black 60%, #181818 80%, black 100%);
+      color: white;
+      padding: 0px 15px;
+      margin: 0px;
+    }
+    a {
+      color: white;
+    }
+    </style>
+  </head>
+  <body>

BIN
Graphics/image-anonymizer/gui/tux.png


+ 160 - 0
Graphics/image-anonymizer/image-anonymizer.sh

@@ -0,0 +1,160 @@
+#!/bin/bash
+
+# CONFIGURATION
+VERSION="0.1"
+TITLE="Image anonymizer"
+
+# ASSETS
+GUIPATH=$(dirname "$0")
+GUIPATH="$GUIPATH/gui" 
+GUIPATH=$(cd "$GUIPATH" && pwd)
+if [[ -z "$GUIPATH" ]] ; then
+  echo "For some reason, the path is not accessible."
+  exit 1
+fi
+
+BASH=$(bash --version | head -1 | awk '{print $4}' | cut -d'(' -f1)
+IM=$(convert -version | head -1 | awk '{print $3}' | cut -d'-' -f1)
+EXIFTOOL=$(exiftool -ver)
+OPTIPNG=$(optipng -version | head -1 | awk '{print $3}')
+DIALOG=$(zenity --version)
+
+# FUNCTIONS
+zenexit() {
+	zenity --window-icon="$GUIPATH/tux.png" \
+		--width="200" \
+		--title="$TITLE" \
+		--error \
+		--text="Operation canceled.\nThank you for using $TITLE." \
+		2> /dev/null
+	rm -f "$HTML"
+	exit 1
+}
+zenstart() {
+	zenity --window-icon="$GUIPATH/tux.png" \
+		--title="$TITLE" \
+		--width="600" --height="400" \
+		--text-info \
+		--html \
+		--filename="$HTML" \
+		--cancel-label="I don't care" \
+		--ok-label="Choose a directory" \
+		2> /dev/null
+}
+zendir() {
+	DIR=$(zenity --window-icon="$GUIPATH/tux.png" --title="$TITLE" --file-selection --directory 2> /dev/null)
+}
+zenend() {
+	zenity --window-icon="$GUIPATH/tux.png" \
+		--title="$TITLE" \
+		--width="800" --height="600" \
+		--text-info \
+		--html \
+		--filename="$HTML" \
+		--cancel-label="Restart" \
+		--ok-label="Exit" \
+		2> /dev/null
+	
+	rm -f "$HTML"
+}
+zenjob() {
+	zenity --window-icon="$GUIPATH/tux.png" \
+		--title="$TITLE" \
+		--progress \
+		--width="600" \
+		--percentage=0 \
+		--cancel-label="Stop everything" \
+		--ok-label="What happened?" \
+		2> /dev/null
+}
+
+# MAIN
+HTML="/tmp/ianon.html.$RANDOM"
+cat "$GUIPATH/top.tpl" > $HTML
+cat "$GUIPATH/start.tpl" \
+	| sed s/'{VERSION}'/"$VERSION"/g \
+	| sed s/'{BASH}'/"$BASH"/g \
+	| sed s/'{DIALOG}'/"$DIALOG"/g \
+	| sed s/'{IM}'/"$IM"/g \
+	| sed s/'{EXIFTOOL}'/"$EXIFTOOL"/g \
+	| sed s/'{OPTIPNG}'/"$OPTIPNG"/g \
+	>> $HTML
+cat "$GUIPATH/bottom.tpl" >> $HTML
+
+zenstart
+ZENSTART=$?
+if [ "$ZENSTART" -eq 0 ]
+then
+  zendir
+	ZENDIR=$?
+
+	if [ "$ZENDIR" -eq 0 ]
+	then
+		cd $DIR;
+		
+		cat "$GUIPATH/top.tpl" > $HTML
+		echo "<h2>Thank you for using "$TITLE".</h2>" >> $HTML
+		(
+			P=0
+			for F in *;
+			do
+					identify -quiet "$F" &> /dev/null
+					if [ "$?" -eq 0 ]
+					then
+						N=$(md5sum "$F" | awk '{print $1}')
+						N="$N.anon.png"
+
+						OLDTYPE=$(file "$F" | cut -d':' -f2)
+						OLDTYPE=$(echo $OLDTYPE | sed 's/ *$//g')
+						if [ ${#OLDTYPE} -gt 64 ]
+						then
+							OLDTYPE="${OLDTYPE:0:61}..."
+						fi
+
+						# This is the important part of the script!
+						convert "$F" "$N" &> /dev/null
+						exiftool -overwrite_original -q -all= "$N" &> /dev/null
+						optipng --silent "$N" &> /dev/null
+						
+						OLDSIZE=$(ls -lah "$F" | awk '{print $5}')
+						NEWSIZE=$(ls -lah "$N" | awk '{print $5}')
+						
+						OLDNAME="$F"
+						if [ ${#OLDNAME} -gt 24 ]
+						then
+							OLDNAME="${OLDNAME:0:21}..."
+						fi
+
+						P=$(($P + 10))
+						echo "$P"
+						echo "# $OLDNAME ($OLDSIZE) $OLDTYPE"
+						echo "<p>&larr; <b>$F</b> ($OLDSIZE)<br>	&bull; $OLDTYPE<br>&rarr; <b>$N</b> ($NEWSIZE)" >> $HTML
+				fi
+			done
+			echo "100"
+			echo "# Thats' all folks!"
+		) | zenjob 
+
+		if [ "$?" -eq 1 ]
+		then zenexit
+		fi
+	fi
+	if [ "$ZENDIR" -eq 1 ]
+	then zenexit
+	fi
+	cat "$GUIPATH/bottom.tpl" >> $HTML
+	zenend
+	ZENEND=$?
+	if [ "$ZENEND" -eq 1 ]
+	then exit
+	fi
+	if [ "$ZENEND" -eq 0 ]
+	then 
+		cd "$GUIPATH"
+		exec ../$(basename $0) && exit
+	fi
+fi
+
+if [ "$ZENSTART" -eq 1 ]
+then zenexit
+fi

BIN
Graphics/image-anonymizer/screenshot-001.png


BIN
Graphics/image-anonymizer/screenshot-002.png


BIN
Graphics/image-anonymizer/screenshot-003.png


BIN
Graphics/image-anonymizer/screenshot-004.png