Need command to mogrify or resize.

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
ohiogto1969
Posts: 8
Joined: 2016-12-09T13:21:49-07:00
Authentication code: 1151

Need command to mogrify or resize.

Post by ohiogto1969 »

I have a folder with 1TB of jpg images some of the images are quite large and I would like to resize all of them that are over a certain size. The largest print size that will ever be needed is 8x10, I read that the minimum size for good prints would be something around 1536x1024.

So my goal is to resize all of the images in the folder and subfolder that are larger than the 1536x1024 to 1536x? . I need to retain the aspect ratio. And what do I do about pictures that are taken in landscape mode

I have read quite a few posts on the board and for the most part they confuse me.

Any help would be appreciated.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Need command to mogrify or resize.

Post by snibgo »

I guess you don't have 1 TB of memory, so you will need to loop through the files. You don't say what shell you use. For bash or Windows BAT, use a "for" command.

For each file, you will be resizing to fit into a square that is 1536x1536, so (for IM v6):

Code: Select all

convert in.ext -resize 1536x1536> out.ext
The aurgment to "-resize" should be quoted, and you may need to escape the ">".
snibgo's IM pages: im.snibgo.com
ohiogto1969
Posts: 8
Joined: 2016-12-09T13:21:49-07:00
Authentication code: 1151

Re: Need command to mogrify or resize.

Post by ohiogto1969 »

I am using windows and I would have to loop through the files. I am afraid I don't understand the syntax of your command. I guess I don't know what should be quoted and escaped. : (
Where would the path go in the command? Forgive me I do not know much about the program.

For example lets say my path is "c:\images" and the file extensions I want to resize are jpgs. What would the command be?
ohiogto1969
Posts: 8
Joined: 2016-12-09T13:21:49-07:00
Authentication code: 1151

Re: Need command to mogrify or resize.

Post by ohiogto1969 »

I did find this so I think I am a little closer.

for %%f in (c:\images\*) do convert .jpg "-resize" 1536x1536> .jpg

I am running a batch file from the command line on a windows 7 system.

The error I am getting is "invalid parameter - -resize"
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Need command to mogrify or resize.

Post by snibgo »

Almost correct.

Code: Select all

md new_directory

for %%F in (c:\images\*.jpg) do convert %%F -resize "1536x1536>" new_directory\%%~nxF
snibgo's IM pages: im.snibgo.com
ohiogto1969
Posts: 8
Joined: 2016-12-09T13:21:49-07:00
Authentication code: 1151

Re: Need command to mogrify or resize.

Post by ohiogto1969 »

I am still getting "Invalid Parameter - -resize" Any ideas? And thanks for sticking with me.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Need command to mogrify or resize.

Post by snibgo »

"Invalid Parameter - -resize"
You are not running ImageMagick's convert.exe. Instead, you are running a Microsoft Windows program. See http://www.imagemagick.org/Usage/windows/#convert_issue
snibgo's IM pages: im.snibgo.com
ohiogto1969
Posts: 8
Joined: 2016-12-09T13:21:49-07:00
Authentication code: 1151

Re: Need command to mogrify or resize.

Post by ohiogto1969 »

Interesting. Thanks for your help. I am going to check this out.
ohiogto1969
Posts: 8
Joined: 2016-12-09T13:21:49-07:00
Authentication code: 1151

Re: Need command to mogrify or resize.

Post by ohiogto1969 »

I am now using the command in a batch file. "for %%F in (c:\images\*.jpg) do magick %%F -resize "1536x1536>" new_directory\%%~nxF"

It seems it only works on files under the root of the directory. I need it to also process sub directories and output the same structure to the output directory. Any help is appreciated.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Need command to mogrify or resize.

Post by GeeMack »

ohiogto1969 wrote:It seems it only works on files under the root of the directory. I need it to also process sub directories and output the same structure to the output directory. Any help is appreciated.
In your script you can use "pushd" to change to the top level directory you want to start in. Then if you use the "/R" switch on your "for" command, it will traverse through the subdirectories from there. At the end of the script you can use "popd" if you need to go back to the original working directory.

Code: Select all

pushd "c:\Your Image Directory\"

for /R %%F in ( *.jpg ) do ...

popd
Or you can specify the working directory right after the "/R" switch, and Windows will work from there down into the directory tree.

Code: Select all

for /R "c:\Your Image Directory\" %%F in ( *.jpg ) do ...
ohiogto1969
Posts: 8
Joined: 2016-12-09T13:21:49-07:00
Authentication code: 1151

Re: Need command to mogrify or resize.

Post by ohiogto1969 »

Thank you, going to try it now.
ohiogto1969
Posts: 8
Joined: 2016-12-09T13:21:49-07:00
Authentication code: 1151

Re: Need command to mogrify or resize.

Post by ohiogto1969 »

That command started processing the files and was working great, the only problem was it did not keep the folder structure the same it was outputting all new resized photos into the root of my new_image directory. If need be I can replace the files under their original directories with the resized image. I am working with a copy of the original folder for testing so I don't have to worry about destroying anything. Thanks
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Need command to mogrify or resize.

Post by GeeMack »

ohiogto1969 wrote:That command started processing the files and was working great, the only problem was it did not keep the folder structure the same it was outputting all new resized photos into the root of my new_image directory.
You can build a Windows script using a "for" loop to traverse a directory tree by using "/R" and "/D" switches on the "for" command. Here's a LINK to a page describing how to do that. Inside that loop you'd "pushd" or "cd /d" to each directory and have another "for" loop that does some things inside the directory. That inside "for" loop is where you'd run your ImageMagick command on all the JPG files there, and even make an output directory for the results if it doesn't already exist.
Post Reply