Page 1 of 1

Need output to have a specific file structure

Posted: 2008-07-16T08:46:53-07:00
by leupi
I am new to Imagemagick and not exactly a Linux guru either so I apologized if this is question has been covered before.

I have an image folder, 'images', with subfolders named after the photographers. The folder 'images' would then contain numerous subfolders such as, 'john', 'frank', 'sue', etc. Those subfolders would then contain numerous photos. I need to resize all of the photos into three different sizes, 192x128, 384x256, and 768x512. I would like to output the files in a structure with the main folder of 'images' and within that, subfolders pertaining to the photographer ('john, 'frank', etc.) and within each of those, subfolders broken down into size ('92x128', '384x256', and '768x512') while appending the image size to the filename, such as image192x128.jpg.

I am able to run the command (from within 'images')

Code: Select all

convert */*.jpg -resize 192x128 newImages
The images resize fine but they are all just dumped into the folder 'newImages'. Is there a way of finishing with the file structure that I am looking for?

Thanks,
Todd

Re: Need output to have a specific file structure

Posted: 2008-07-16T10:19:43-07:00
by fmw42
One way is to use mogrify and path

see

http://www.imagemagick.org/Usage/basics/#mogrify

Re: Need output to have a specific file structure

Posted: 2008-07-16T11:04:37-07:00
by leupi
Thanks for the suggestion. I am unsure how to make -path work as I would like it to create the folders based on the original folder structure (and add some subfolders). I imagine that I will need to write a bash script to create the folder structure that I want to use and then run Imagemagick to populate it with the resized images.

Thanks,
Todd

Re: Need output to have a specific file structure

Posted: 2008-07-16T11:55:30-07:00
by leupi
I created a bash script that created the needed file structure. I now need to resize the images and move them to the proper folder. I was able to accomplish this with one small issue, I want the filenames to stay the same (or even better to append 192x128 to the filename). I am running this:

Code: Select all

convert /folder/*.jpg -resize 192x128 /images/subfolderOne/192x128/
That causes all of the images in /folder to be resized and to go where I want them; however, they are named '-0', '-1', '-2', etc. I would like to at least be able to keep the existing filename or even better, append 192x128 to the end of it as filename192x128.jpg. Any thoughts?

Thanks,
Todd

Re: Need output to have a specific file structure

Posted: 2008-07-16T15:39:48-07:00
by fmw42
never mind - it did not work

Re: Need output to have a specific file structure

Posted: 2008-07-16T16:40:46-07:00
by anthony
Use mogrify not convert

Code: Select all

  cd directory
   mogrify  -resize 192x128   '*.jpg'
Or to save into a different directory

Code: Select all

  cd source_directory
  mogrify -path dest_dir  -resize 192x128   '*.jpg'
WARNING: danger, mogrify can overwrite the original image if you are not careful!
See IM Examples, Basics, Mogrify. You may also like to look at thumbnailing.


For a whole directory structure, you will need some type of shell looping. The Mogrify section describes some shell script options for this.

Ideally you would write a script, or use a higher level package to generate smaller 'web viewing' images and thumbnails , as well as index pages. There are lots of options out there, though to me most of then goes overboard with complexity, meta-data and methodology.

Re: Need output to have a specific file structure

Posted: 2008-07-17T05:41:10-07:00
by leupi
That seems to do what I needed. I appreciate the help.

Todd