From: Woody on
Chris Ridd <chrisridd(a)mac.com> wrote:

> On 2010-05-27 15:15:47 +0100, Woody said:
>
> > If I did:
> >
> > find . -name "*.jpg" -exec convert -resize 62x62 '{}' s_'{}' ';'
> >
> > it failed saying htings like:
> > Can't open file s_ ./blah.jpg
>
> Because find adds the directory you're starting from (ie ".") to the
> front of every filename.
>
> > How would I have done that?
>
> I'd use a shell loop, and sed if I really wanted to munge the filename
> (like changing extensions), something like this:
>
> for jpeg in *.jpg; do
> fixed=`echo "$jpeg" | sed -e 's/^/s_/'`
> convert -resize 62x62 "$jpeg" "$fixed"
> done

Cool - thanks. I still have some other images to do!

--
Woody

www.alienrat.com
From: Richard Kettlewell on
Chris Ridd <chrisridd(a)mac.com> writes:
> On 2010-05-27 15:15:47 +0100, Woody said:

>> If I did:
>>
>> find . -name "*.jpg" -exec convert -resize 62x62 '{}' s_'{}' ';'
>>
>> it failed saying htings like:
>> Can't open file s_ ./blah.jpg
>
> Because find adds the directory you're starting from (ie ".") to the
> front of every filename.
>
>> How would I have done that?
>
> I'd use a shell loop, and sed if I really wanted to munge the filename
> (like changing extensions), something like this:
>
> for jpeg in *.jpg; do
> fixed=`echo "$jpeg" | sed -e 's/^/s_/'`
> convert -resize 62x62 "$jpeg" "$fixed"
> done

That doesn't recurse into subdirectories, which the find version does.
(The business with sed is also a rather OTT way of saying "s_$jpeg".)

This ought to do the job with subdirectories included:

find . -name "*.jpg" -print0 | \
xargs -n1 -r0 bash -c \
'convert -resize 62x62 "$1" "${1%/*}/s_${1##*/}"' --

--
http://www.greenend.org.uk/rjk/
From: Chris Ridd on
On 2010-05-27 17:49:48 +0100, Richard Kettlewell said:

> Chris Ridd <chrisridd(a)mac.com> writes:
>> On 2010-05-27 15:15:47 +0100, Woody said:
>
>>> If I did:
>>>
>>> find . -name "*.jpg" -exec convert -resize 62x62 '{}' s_'{}' ';'
>>>
>>> it failed saying htings like:
>>> Can't open file s_ ./blah.jpg
>>
>> Because find adds the directory you're starting from (ie ".") to the
>> front of every filename.
>>
>>> How would I have done that?
>>
>> I'd use a shell loop, and sed if I really wanted to munge the filename
>> (like changing extensions), something like this:
>>
>> for jpeg in *.jpg; do
>> fixed=`echo "$jpeg" | sed -e 's/^/s_/'`
>> convert -resize 62x62 "$jpeg" "$fixed"
>> done
>
> That doesn't recurse into subdirectories, which the find version does.

True enough.

> (The business with sed is also a rather OTT way of saying "s_$jpeg".)

Yes, because it is what I generally use when doing more involved
filename alterations such as changing file extensions.

>
> This ought to do the job with subdirectories included:
>
> find . -name "*.jpg" -print0 | \
> xargs -n1 -r0 bash -c \

Interesting - do you need -r0 or just -0? Also find's man page
recommends using -X to be safe.

> 'convert -resize 62x62 "$1" "${1%/*}/s_${1##*/}"' --

:-)
--
Chris

From: Woody on
Richard Kettlewell <rjk(a)greenend.org.uk> wrote:

> Chris Ridd <chrisridd(a)mac.com> writes:
> > On 2010-05-27 15:15:47 +0100, Woody said:
>
> >> If I did:
> >>
> >> find . -name "*.jpg" -exec convert -resize 62x62 '{}' s_'{}' ';'
> >>
> >> it failed saying htings like:
> >> Can't open file s_ ./blah.jpg
> >
> > Because find adds the directory you're starting from (ie ".") to the
> > front of every filename.
> >
> >> How would I have done that?
> >
> > I'd use a shell loop, and sed if I really wanted to munge the filename
> > (like changing extensions), something like this:
> >
> > for jpeg in *.jpg; do
> > fixed=`echo "$jpeg" | sed -e 's/^/s_/'`
> > convert -resize 62x62 "$jpeg" "$fixed"
> > done
>
> That doesn't recurse into subdirectories, which the find version does.
> (The business with sed is also a rather OTT way of saying "s_$jpeg".)
>
> This ought to do the job with subdirectories included:
>
> find . -name "*.jpg" -print0 | \
> xargs -n1 -r0 bash -c \
> 'convert -resize 62x62 "$1" "${1%/*}/s_${1##*/}"' --

Thanks, although in this case it is a flat directory of images that are
being converted

--
Woody

www.alienrat.com
From: Richard Kettlewell on
Chris Ridd <chrisridd(a)mac.com> writes:
> Richard Kettlewell said:

>> This ought to do the job with subdirectories included:
>>
>> find . -name "*.jpg" -print0 | \
>> xargs -n1 -r0 bash -c \
>
> Interesting - do you need -r0 or just -0? Also find's man page
> recommends using -X to be safe.

The -r is habit, it's not really required with -n1.

-X doesn't make any sense with -print0.

--
http://www.greenend.org.uk/rjk/