You are not logged in.

#1 2014-03-19 09:31:43

ytsejam
Member
Registered: 2012-02-10
Posts: 53

(solved)How to use jpegoptim recursively in subfolders.

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

#2 2014-03-19 09:43:36

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: (solved)How to use jpegoptim recursively in subfolders.

ytsejam wrote:

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

#3 2014-03-19 09:44:40

ytsejam
Member
Registered: 2012-02-10
Posts: 53

Re: (solved)How to use jpegoptim recursively in subfolders.

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

#4 2014-03-19 09:45:25

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: (solved)How to use jpegoptim recursively in subfolders.

jpegtran is in the repos, in libjpeg-turbo package:

$ pkgfile jpegtran
extra/libjpeg-turbo

Offline

#5 2014-03-19 09:48:22

ytsejam
Member
Registered: 2012-02-10
Posts: 53

Re: (solved)How to use jpegoptim recursively in subfolders.

ok seen that ... trying now.

Last edited by ytsejam (2014-03-19 09:50:11)

Offline

#6 2014-03-19 09:50:20

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: (solved)How to use jpegoptim recursively in subfolders.

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

#7 2014-03-19 10:00:00

ytsejam
Member
Registered: 2012-02-10
Posts: 53

Re: (solved)How to use jpegoptim recursively in subfolders.

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

#8 2014-03-19 10:10:48

ytsejam
Member
Registered: 2012-02-10
Posts: 53

Re: (solved)How to use jpegoptim recursively in subfolders.

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

#9 2014-03-19 10:17:00

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: (solved)How to use jpegoptim recursively in subfolders.

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

#10 2014-03-19 10:19:52

ytsejam
Member
Registered: 2012-02-10
Posts: 53

Re: (solved)How to use jpegoptim recursively in subfolders.

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

#11 2014-03-19 10:21:06

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: (solved)How to use jpegoptim recursively in subfolders.

The script for jpegtran did work for me.

Offline

#12 2014-03-19 10:23:30

ytsejam
Member
Registered: 2012-02-10
Posts: 53

Re: (solved)How to use jpegoptim recursively in subfolders.

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

#13 2014-03-19 10:25:52

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: (solved)How to use jpegoptim recursively in subfolders.

ytsejam wrote:

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).

ytsejam wrote:

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

Board footer

Powered by FluxBB