Page 1 of 1

Convert or mogrify batch files in multiple directory

Posted: 2018-05-08T11:45:59-07:00
by NoWayHome
Hi.

I m working on linux, but i m not a command line guru so i need your help.

I have several images in several directory
directory\sub1
directory\sub2
directory\sub3
...

I succes to found a command to optimise them :

find directory -iname "*.jpg" | xargs mogrify *.jpg -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace sRGB *.jpg

It's Working fine, it's replace orignal file my optimised file in correct subdir.

But my goal is to resize, optimise AND rename ..

So i tried

find directory -iname "*.jpg" | xargs mogrify -set filename:name %f -write 'suffix-%[filename:name]' -resize 177x -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace sRGB *.jpg

And it's not workink as i want.
It's write new file in main directory, not in each sub.

How to solve my problem ?
Thanks

Re: Convert or mogrify batch files in multiple directory

Posted: 2018-05-08T14:19:28-07:00
by fmw42
Mogrify will not allow renaming. You will have to write a script loop over each image and write a specific name for each output. Or if you are on ImageMagick 7, you might be able to do the renaming for all files with your 'suffix-%[filename:name]' scheme in one command line, memory permitting.

Please, always provide your IM version and platform when asking questions, since syntax may differ. Also provide your exact command line and if possible your images.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at http://www.imagemagick.org/discourse-se ... f=1&t=9620

For novices, see

http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown

Re: Convert or mogrify batch files in multiple directory

Posted: 2018-05-09T01:07:08-07:00
by NoWayHome
Hi.

I allready check lot of post here + other website.
and dont found the correct answer.

Platform : Ubuntu
Imagemagick : ImageMagick 7.0.7-31

i made a mistake in my first post .
I want to write a new file.

i have more than 1500 images in 300 directories.
my goal is to resize, optimise AND write the new image as a new file ..

I have

directory\sub1\image-01.jpg
directory\sub2\image-other-name-01.jpg
directory\sub3\image-different-name-01.jpg

i try to have

directory\sub1\image-01.jpg + directory\sub1\rz-image-01.jpg
directory\sub2\image-other-name-01.jpg + directory\sub2\rz-image-other-name-01.jpg
directory\sub3\image-different-name-01.jpg + directory\sub3\rz-image-different-name-01.jpg

The command line

find directory -iname "*.jpg" | xargs mogrify -set filename:name %f -write 'suffix-%[filename:name]' -resize 177x -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace sRGB *.jpg

is not working as i want

Re: Convert or mogrify batch files in multiple directory

Posted: 2018-05-09T06:23:50-07:00
by snibgo
NoWayHome wrote:find ... xargs mogrify ... *.jpg
"find" makes a list of filenames. "xargs" calls "mogrify" which uses the input "*.jpg", to which xargs appends each of the filenames produced by "find".

So, why do you have "*.jpg" as an argument to mogrify? What do you expect that to do?

I suggest you read documentation (eg man pages) for "find" and "xargs".

Re: Convert or mogrify batch files in multiple directory

Posted: 2018-05-09T09:43:28-07:00
by NoWayHome
snibgo wrote: 2018-05-09T06:23:50-07:00
NoWayHome wrote:find ... xargs mogrify ... *.jpg
"find" makes a list of filenames. "xargs" calls "mogrify" which uses the input "*.jpg", to which xargs appends each of the filenames produced by "find".

So, why do you have "*.jpg" as an argument to mogrify? What do you expect that to do?

I suggest you read documentation (eg man pages) for "find" and "xargs".
Thanks.
This arg was useless.

But it's not solving my main problem that is it's write file in main directory and not and each dir.
That's the problem i cant solve.

The first command ( replace ) was good
The second commande ( write new file ) dont works like i want.

Re: Convert or mogrify batch files in multiple directory

Posted: 2018-05-17T12:20:58-07:00
by NoWayHome
so anyone ?