Page 1 sur 1

Simple image reducer

Posté : 26 sept. 2018, 17:18
par alphonse
Bonsoir,
c'est encore moi ; je fignole mon Xubuntu récemment installé...
Comme indiqué dans le sujet "Simple image reducer " ne se lance pas. Problème connu ? Un logiciel de remplacement ?

Re: Simple image reducer

Posté : 26 sept. 2018, 19:46
par Motux
Bonsoir,

J'utilise régulièrement Simple Image Reducer 1.0.2 sous Xubuntu 16.04.3... J'ai fait un test rapide dans une machine virtuelle Xubuntu 18. Effectivement, le programme ne démarre pas !
Rien de plus à dire pour le moment.

A+
Maurice

Re: Simple image reducer

Posté : 28 sept. 2018, 09:38
par cinaptix
Bonjour,
Un simple script fait la même chose en local et éventuellement par lot.

Re: Simple image reducer

Posté : 29 sept. 2018, 06:44
par alphonse
Bonjour à vous,
un simple script...oui mais lequel ?

Re: Simple image reducer

Posté : 29 sept. 2018, 16:13
par cinaptix
Voilou !

Code : Tout sélectionner

#!/bin/bash
#
# Author : Mathieu Vilaplana <mathieu@creationgif.com>
# Author : Matthieu MARC <matthieu.marc@wanadoo.fr>
#
# Copyright (C) 2005,2006  Charles Bouveyron <charles.bouveyron@free.fr>
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# 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.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

# pour l'internationalisation des messages	
# to generate the i18n file from .po file :
# $ msgfmt -o .locale/fr/LC_MESSAGES/nis.mo .locale/fr/LC_MESSAGES/fr.po
export TEXTDOMAIN="nis"
export TEXTDOMAINDIR=`dirname $0`"/.locale/"

MAXCPT=50000;

nb_images=0;
selection="";

txt_error="`gettext 'error'`"
#test if a file has been selected
if [ $# -eq 0 ]; then
	# zenity --error --title=$txt_error --text="`gettext 'You must select at least 1 file to process'`"
	here=`pwd`"/."
	files=`zenity --file-selection --multiple --separator="|" --filename="$here"`"|"
	#if $? != 0, user click on cancel button, so exit
	if [ "$?" != 0 ] ; then
		exit
	fi
	cpt=0
	# I put all filename in $selection here because I didn't managed to put filenames with whitespace in $*
	while [ ${#files} -gt 0 ]; do
		f="`echo $files |cut -f1 -d'|'`"
		isimage=`file -bi "$f" |grep -c image`
		if [ $isimage -eq 1 ]; then
			selection[$nb_images]=$f
			let "nb_images++"
		fi
		files=`echo $files |cut -f2- -d"|"`
		let "cpt++"
		# only to avoid infinite loop (do not occured normaly, but nobody never know.. perhaps!)
		if [ $cpt -gt $MAXCPT ]; then
			shift
		fi
	done
fi

#===================================
#       SELECT SIZE DIALOG
txt_text="`gettext 'Choose which size to scale to'`"
txt_title=$txt_text
txt_size="`gettext 'size'`"

imgsize=`zenity --title "$txt_title" --text "$txt_text" --list --radiolist --separator=" " --column="" --column="$txt_size" FALSE "160x120" FALSE "320x240" FALSE "640x480" FALSE "800x600" FALSE "1024x768" FALSE "1280x960" TRUE "1440x1184" FALSE "1600x1200" FALSE "2048x1536" FALSE "2400x1800" --height=340`

#if $? != 0, user click on cancel button, so exit
if [ "$?" != 0 ] ; then
	exit
fi

#user must select a target size
imgsize=`echo $imgsize | sed 's/ max//g'`
if [ ! "$imgsize" ]; then
	zenity --error --title=$txt_error --text="`gettext 'select a target size'`"
	# just restart myself (more user friendly I think)
	($0 "$*")&
	exit
fi

#transform 640x480 en 640x640 for convert to respect proportions
himgsize=$imgsize
val1=`echo "$imgsize" | awk -F'x' '{ print $1  }'`
imgsize="${val1}x${val1}"

#       END SELECT SIZE DIALOG
#=========================


#Select only images
while [ $# -gt 0 ]; do
	isimage=`file -bi "$1" | grep -c image` 
	if [ $isimage -eq 1 ]; then
		selection[$nb_images]=$1
		let "nb_images++"
	else
		isdir=`file -b "$1" |grep -c directory`
		if [ $isdir -eq 1 ]; then
			for f in `ls -1 "$1"`; do
				isimage=`file -bi "$1/$f" |grep -c image`
				if [ $isimage -eq 1 ]; then
					selection[$nb_images]="$1/$f"
					let "nb_images++"
				fi
			done
		fi
	fi
	shift
done

n=$nb_images
let "n=n-1"
(for i in `seq 0 $n`;do
	picture=${selection[$i]}
	img_filename=`basename "$picture"`
	img_dirname=`dirname "$picture"`

	#create directory if not exist and at least one image to process
	if [ ! -d "$img_dirname/$himgsize"  ]; then
		mkdir -p "$img_dirname/$himgsize"
	fi

	let "compteur += 1"
	echo "`gettext '# Processing image'` $compteur / $nb_images $img_filename ..."
	convert -quality 80 -resize $imgsize "$picture" "$img_dirname/$himgsize/$img_filename"
	#convert -quality 80 -resize $imgsize "$picture" $himgsize/"$picture"
	let "progress = compteur*100/nb_images"
	echo $progress
done
) | zenity --progress --auto-close --title="`gettext 'Scaling images'`" --text="`gettext 'Processing images ...'`"  --percentage=0

(thunar "`dirname \"${selection[0]}\"`/$himgsize") &
exit
En faire une action personnalisée dans Thunar et le tour est joué !

Re: Simple image reducer

Posté : 29 sept. 2018, 21:50
par Motux
Bonsoir,

Ce script mérite un très grand merci !

J'ai juste patiné un peu pour la création de l'action personnalisée... Je ne connaissais pas du tout. Pour moi problème résolu !

A+
Maurice

Re: Simple image reducer

Posté : 30 sept. 2018, 09:07
par alphonse
Moi, je ne suis pas au niveau, je vais, comme sous Linux-mint, continuer à utiliser XnConvert.
Merci d'être intervenu.

Re: Simple image reducer

Posté : 30 sept. 2018, 12:05
par cinaptix
Bonjour,

Les scripts permettent dans GNU/Linux de pallier simplement à des manques ou automatiser certaines opérations. Une fois associés à une action personnalisées, tout est simple.

Utiliser le script en 3 points :
1 - Créer (s'il n'existe pas) un dossier ".scripts" dans son /home/user/
2 - Copier le script dans un fichier texte qu'on nommera "Redimensionner". Avec un clic droit permissions cocher " Autoriser ce fichier a être exécuté comme un programme", le copier dans le dossier ".scripts".
3 - Dans le gestionnaire de fichier ouvrir "Édition > Configurer les actions personnalisées". Dans la boîte de dialogue cliquer sur le + et remplir la boîte qui s'ouvre en faisant pointer l'action sur le fichier "Redimensionner" du dossier ".scripts" avec %F à la fin du chemin. Dans l'onglet "Conditions d'apparition" cocher l'item "Fichiers images"

Il suffira ensuite de cliquer droit sur une ou plusieurs images et choisir la taille dans la boîte de dialogue. C'est tout.