As always, backup all data.
Bryan Schmiedeler wrote:
That is, I need a scrip to open the the file and change it to 500x500 - then the graphics person could do the cropping, and then a script to just save the file to a reasonable size.
If you prefer not to auto-crop as described in the posts above...
Scale a source image to a different aspect ratio results in either horizontal squeezing or vertical squashing of the image. Simply batch crop a 500 x 500 pixel area at a single specified location from images in a set and there is no guarantee the face will even remain in all the crops given their varied compositions. Batch crop a 500 x 500 pixel area with the face centered, assuming the face of the subject for all the images in a set could be centered by some method other than face detection, too little of the image may remain to crop in a pleasing way. The image area remaining in the crop is of course dependent on the dimensions of the source image.
Crop and resize an image with a minimum of 500 pixels in the smallest dimension, crop to frame the subject and resize to the specified 500 x 500 pixels, the image is degraded.
If reducing the dimensions of an image prior to manual cropping is a requirement, with the assumption that the subject in an image is relatively centred and that their face is closer to the top of the image than the horizontal midline, you might try using a more generous crop without resizing as achieved using the following ImageMagick command. Keep in mind the image area remaining in the crop for each image will be variable due to the variable dimensions among the set of source images:
mogrify -crop 1000x1000+0+0 -gravity North +repage -strip -path /path/to/output_images/ /path/to/input_images/*.jpg
Ideally, in regards to image quality, crop and resize an image only as necessary. If resizing is required, do it once and only after cropping to minimize degrading the image. Assuming it could be scripted as you suggest, there is no image or efficiency benefit to batch resizing prior to manual cropping of individual images. There is an efficiency benefit to batch processing after manual cropping. Although you can batch resize in Preview, ImageMagick offers more control over parameters.
.
A suggested workflow using Preview and ImageMagick, as well as Finder and Terminal:
To prevent damage or loss, it is a best practice to never edit original images. Make two copies of the folder of original jpeg images on the Desktop. Rename one source_photos and the other working_photos. The source_photos folder is to copy individual images if necessary without the need to resort to the secured folder of original images. The working_photos folder is for opening and saving images while cropping. Create an empty third folder on the Desktop named processed_photos for saving to after resizing.
Open Preview. From the menu bar navigate to Preview > Preferences > General and make sure “Open all files in one window” is selected. Using Application Switcher, Command-Tab between Preview and Finder. Open and maximize a Finder window in column view. Click the working_photos folder. Decide how many images to open in Preview; one hundred for example. Hold down the Shift key and click the one hundredth image file. This will select all the images from the first to the hundredth. Assuming images open in Preview by default, press the Command-O keys to open them in a Preview window. If Preview isn’t the default app for opening images, Control-click and select Preview. Either way, maximize the Preview window once open. In Preview, select Thumbnails from the View menu if the images don’t appear in the sidebar. The filename of the first thumbnail image in the sidebar should be highlighted with the corresponding image in the content area displayed. If not highlighted, click on the first image in the sidebar. Press the Command-A to select all the images in the sidebar. Press the Command-9 keys to zoom all the images to fit to the size of the content area.
If a cross cursor doesn’t automatically appear in the content area when the cursor is hovering over the image, click the Markup Toolbar menu and select Rectangular Selection from the Selection Tools menu. Hold down the Shift key and drag the cursor to create a square Rectangular Selection frame of the proximate desired size for cropping. Position the cursor anywhere inside the frame. The cursor will change to an open hand icon. Click and drag the closed hand cursor to reposition the frame to the desired location. Resize the frame as necessary by positioning the cursor over a corner of the frame until a corner resize cursor appears; click and drag to resize.
When satisfied with the framing of the subject in the image, release the Shift key and press the Command-K keys to crop. Press the Command-Z keys to reverse the crop if you wish to redo it.
Press the Command-9 keys to zoom the cropped image to fit to the size of the content area.
Press the Arrow-down key to move to the next image. Repeat the cropping process. If using a trackpad, optionally swipe upward with a two finger gesture to move down to the next image. When finished cropping the last image, click in the sidebar and press the Command-A keys to select all the images. Press the Command-S keys to save. Close the Preview window.
Press the Command-Tab keys to select Finder in the Application Switcher. In the Finder window you opened previously, click the hundredth-and-first image file in the working_photos folder. This will deselect the first hundred image files and highlight the image file you clicked on. Hold down the Shift key and click the two-hundredth image file. All one hundred of the second hundred images will be highlighted. Press the Command-O keys to open them in Preview. Repeat the cropping process as before.
Prior to beginning the cropping process, you may want to organize the image files in the working_photos folder into subfolders. For example, ten sequentially numbered subfolders named employee_photos containing one hundred images each for the approximately one thousand images. You may want to do this to simplify organization, to make it easier to track which images have been cropped over multiple sessions, or to distribute copies of a folder or folders to different individuals to process. You can do this using Terminal with the following commands.. First change to the working_photos directory:
cd ~/Desktop/working_photos
Confirm the working directory you are in:
pwd
When confirmed, create the subdirectories and move the images into them, one hundred images per subdirectory:
i=0; for f in *; do d=employee_photos_$(printf %03d $((i/100+1))); mkdir -p $d; mv "$f" $d; let i++; done
Confirm the subdirectories were created:
ls -1
Note that you can select all the images in a subfolder for cropping by clicking on one image file and pressing the Command-A keys to select all. As you finish cropping the images in each employee_photos subfolder, you may want to tag them as complete, with green for instance. You may also want to use a red tag for a subfolder if all the images within haven’t been cropped, as would happen if not completed over a single session, or if the processing of subfolders is non-sequential . You can select multiple images to tag.
When all the images in all the subfolders have been cropped, you can move the images back into the working_photos parent folder and delete all the empty employee_photos subfolders. First though, backup the the working_folders folder by duplicating it on the Desktop. Then, in Terminal change to the working_photos directory:
cd ~/Desktop/working_photos
Confirm the working directory you are in:
pwd
When confirmed, copy all the files in the employee_photos subdirectories into the working_photos parent directory and remove the subdirectories using the -i switch for interactive mode:
find ./ -name '*.jpg' -exec mv '{}' ./ \; && rm -r -i ./*/
You’ll need to confirm removal of each subdirectory by typing “y” and pressing the Return key. If you prefer not to do this, you can substitute the following command without the need to confirm the removal of each subdirectory:
find ./ -name '*.jpg' -exec mv '{}' ./ \; && rm -r ./*/
Command-Tab to Finder to confirm the subfolders were deleted and all the images were moved to the working_photos folder. Whether or not you decide to create and employ subfolders in your workflow, once all the images have been cropped, the final step is to batch process all the images to the specified dimensions and file size. The following command uses ImageMagick in Terminal:
mogrify -define jpeg:extent=55kb \
-resize '500x500^’ \
+repage -strip \
-path ~/Desktop/processed_photos/ \
~/Desktop/working_photos/*.jpg
Confirm the processing of the images by opening the processed_photos folder in the column view of Finder. Keep in mind that differences in image quality between the final cropped and resized images depends in part on differences in the dimensions of the original images and the percentage of area cropped relative to each whole image.
Tested with OS X Yosemite 10.10.5, and ImageMagick 6.9.3.