You are not logged in.
Hello ,
I want to optimize some images without changing names with many subfolders loaded.
I am not good at shell script. I found this for jpegtran but package does not work.
How can I modifiye it for jpegoptim?
#! /bin/sh
# Usage 1:
# optimize-images.sh /images/dir
#
# Usage 2:
# cd /images/dir
# optimize-images.sh
EXTENSIONS="jpe?g"
if [ -z "$1" ]; then
DIR="`pwd`"
else
DIR="$1"
fi
# Optimize JPEG images
find "$DIR" -regextype posix-egrep -regex ".*\.($EXTENSIONS)\$" -type f | xargs -I{} jpegtran -optimize -progressive -outfile "{}.optimized" "{}"
# Rename xxx.jpg.optimized -> xxx.jpg
find "$DIR" -name '*.optimized' -print0 | while read -d $'\0' file; do
chown $(stat -c "%U:%G" "${file%.optimized}") "$file"
chmod $(stat -c "%a" "${file%.optimized}") "$file"
mv -f "$file" "${file%.optimized}";
done
ps1: also found this while google in but I dont know where to write it :
optimize() {
jpegoptim *.jpg --strip-all
for i in *
do
if test -d $i
then
cd $i
echo $i
optimize
cd ..
fi
done
echo
}
optimize
Last edited by ytsejam (2014-03-19 10:20:12)
Offline
I found this for jpegtran but package does not work.
What exactly do you mean?
Have you tried substituting one command ('jpegtran -optimize -progressive -outfile') for another?
Offline
Jpegtran installation does not work in AUR repo. I cant install it. The other one does not have any docs I dont know if has the same commands.
Last edited by ytsejam (2014-03-19 09:45:29)
Offline
jpegtran is in the repos, in libjpeg-turbo package:
$ pkgfile jpegtran
extra/libjpeg-turbo
Offline
ok seen that ... trying now.
Last edited by ytsejam (2014-03-19 09:50:11)
Offline
You shouldn't be just copy-pasting commands you don't understand: https://wiki.archlinux.org/index.php/FA … ge_is_X.3F
Install libjpeg-turbo with pacman.
Offline
It is installed.. I checked it and I can see with pkgfile. I am trying to find out where to write that script now .
Offline
The steps, I follow are :
1) I added following to ~/.bashrc
optimize() {
jpegoptim *.jpg --strip-all
for i in *
do
if test -d $i
then
cd $i
echo $i
optimize
cd ..
fi
done
echo
}
2) 'echo $PATH' gives me
/home/ytsejam/.gem/ruby/2.1.0/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/ytsejam/.gem/ruby/2.0.0/bin
The error is :
optimize
bash: optimize: command not found
Offline
Run
. ~/.bashrc
(there is a dot, a space and your ~/.bashrc)
and try again.
Edit: Wait a sec, this function seems to call itself ...
Last edited by karol (2014-03-19 10:18:29)
Offline
karol,
Thank you for efforts , I needed to logout and login .
optimize() {
jpegoptim *.jpg --strip-all
for i in *
do
if test -d $i
then
cd $i
echo $i
optimize
cd ..
fi
done
echo
}
works with jpegoptim. I think the same will occur with jpegtran. I had a $PATH value for ruby , it was ruining my bashrc. I commented it and works now.
Offline
The script for jpegtran did work for me.
Offline
I checked .bashrc problems and have seen your answer here https://bbs.archlinux.org/viewtopic.php?id=118898.
Used this to solve the problem.I am sure jpegtran will also work.
Thank you again.
Offline
It is installed.. I checked it and I can see with pkgfile. I am trying to find out where to write that script now .
pkgfile shows what's in the sync databases (in the repos), not what is in the local databases (what do you have on your computer).
karol,
Thank you for efforts , I needed to logout and login .optimize() { jpegoptim *.jpg --strip-all for i in * do if test -d $i then cd $i echo $i optimize cd .. fi done echo }
works with jpegoptim. I think the same will occur with jpegtran. I had a $PATH value for ruby , it was ruining my bashrc. I commented it and works now.
How exactly were you trying to use the script for jpegtran? Did you put it in your ~/.bashrc? You don't have to put your script location in your $PATH to run it, you just need to use the full path then.
Offline