Convert a Picture

We want to find pictures over a certain size in MB.

We want to resize them so they are only 1000px wide.

We want to compress the quality to 80%.

find /home/bigmac/public_html/wp-content/plugins/wp-easycart-data/products/pics4 -size +1M | while read i; do j="${i// /\ }";k="${j//(/\(}"; l="${k//)/\)}"; m="${l//&/\&}"; n=$(echo "$m"| sed 's/$/\$/g');  echo convert -resize 1000 -quality 80% $n $n;done

find /home/bigmac/public_html/wp-content/plugins/wp-easycart-data/products/pics4 -size +1M | while read I
    j=”${i// /\ }”
    n=$(echo “$m”| sed ‘s/\$/\\$/g’)
    echo convert -resize 1000 -quality 80% $n $n

So what does this all do?

First, we are running the find command against a Directory looking for files over 1MB.

While we are doing this we read the results as an array and look at each item as a variable called “i”.

We now do work on that variable “i”.

The work we are doing is to look in “i”, and whenever we find ” “, a space we replace the space with “\ “. This makes the new variable, “j” readable later in an echo.

Next in this new variable “j”, we look in it and search for “(” and replace with “\(“, and put in “k”.

Then “l” is “)” to “\)”.

Then “m” is “&” to “\&”.

Finally, we want to do “$”, but this is harder so we use sed.

And now we want to echo our command.

The command is convert, with a resize down to a width of 100px and a quality of 80%.