From: Hugo Villeneuve Date: Thu, 31 Oct 2024 22:36:48 +0000 (-0400) Subject: Ajout hv-resize X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=6ae54418c7c292bd2c574094a48d6e9b50043e70;p=hvutilities.git Ajout hv-resize --- diff --git a/scripts/Makefile.am b/scripts/Makefile.am index 7a19809..af8f969 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -48,6 +48,7 @@ dist_bin_SCRIPTS = \ flac2ogg flac2mp3 \ hv-scan \ hvpdf-rotate \ + hv-resize \ tape-backup tape-backup-mult tape-list tape-restore diff --git a/scripts/hv-resize b/scripts/hv-resize new file mode 100755 index 0000000..330444f --- /dev/null +++ b/scripts/hv-resize @@ -0,0 +1,106 @@ +#!/bin/bash + +# Change la taille des images d'un répertoire + +PROG_NAME=$(basename $0) + +size="1024x768" + +print_usage() +{ + echo "${PROG_NAME} -- Change la taille des images d'un répertoire" + echo "Usage: ${PROG_NAME} [OPTIONS...] SRCDIR" + echo + echo "Options:" + echo " -h display this help and exit" + echo " -d répertoire de destination (optionel)" + echo " -s format (défaut = ${size})" + echo +} + +while getopts "d:hs:" flag ;do + case ${flag} in + h) + print_usage + exit 0 + ;; + d) + destdir="${OPTARG}" + ;; + s) + size="${OPTARG}" + ;; + ?) + echo "${PROG_NAME}: Option invalide: ${OPTARG}." + echo "Essayez \`${PROG_NAME} -h' pour plus d'informations." + exit 1 + ;; + esac +done +shift `expr "${OPTIND}" - 1` + +# `$#' now represents the number of arguments after the options. +# `$1' is the first argument, etc. +if [ $# -gt 1 ]; then + echo "${PROG_NAME}: Too many arguments." + echo "Essayez \`${PROG_NAME} -h' pour plus d'informations." + exit 1 +fi + +if [ ${#} -ne 1 ]; then + echo "${PROG_NAME}: Nom de répertoire manquant." + echo "Essayez \`${PROG_NAME} -h' pour plus d'informations." + exit 1 +fi + +dir=${1} + +if [ ! -d "${dir}" ]; then + echo "${PROG_NAME}: Répertoire absent: ${dir}" + echo "Essayez \`${PROG_NAME} -h' pour plus d'informations." + exit 1 +fi + +if [ "${destdir}" != "" ]; then + if [ -d "${destdir}" ]; then + echo "${PROG_NAME}: Répertoire de destination présent: ${destdir}" + echo "Essayez \`${PROG_NAME} -h' pour plus d'informations." + exit 1 + fi + + mkdir -p ${destdir} + cp -a ${dir}/* ${destdir} + dir="${destdir}" +fi + +# Rename JPG -> jpeg +src="$(find ${dir} -name \*.JPG)" + +if [ "${src}" != "" ]; then + for f in ${src}; do + mv -- "${f}" "${f%.JPG}.jpeg" + done +fi + +# Rename jpg -> jpeg +src="$(find ${dir} -name \*.jpg)" + +if [ "${src}" != "" ]; then + for f in ${src}; do + mv -- "${f}" "${f%.jpg}.jpeg" + done +fi + +# Convert jpeg: +src="$(find ${dir} -name \*.jpeg)" + +if [ "${src}" != "" ]; then + mogrify -resize ${size} ${dir}/*.jpeg +fi + +# Convert png: +src="$(find ${dir} -name \*.png)" + +if [ "${src}" != "" ]; then + mogrify -resize ${size} ${dir}/*.png +fi