I'd like to take a folder of images of various sizes and have them cropped into a 600x600 grid square, cut out from the middle of the image. Is there a program that can automatically resize and crop to these dimensions, and then output as a compressed .png file? For images that are smaller than 600x600, I'd like the program to increase the size of the image to that dimension.
-
1\$\begingroup\$ I checked my Irfanview, and its batch crop is static with only the option to start from corners and a fixed offset. It cannot do the centering and the conditional resize asked for by the OP. It is not fit for variable image sizes. \$\endgroup\$– Michael NielsenCommented Sep 13, 2012 at 10:49
-
1\$\begingroup\$ I was very hopeful XnConvert might do what you're after but like IrfanView it won't do a centred crop on arbitrary image sizes. \$\endgroup\$– Mark WhitakerCommented Oct 3, 2012 at 7:44
11 Answers
Photoshop's Batch command can do this. You would essentially 'record' yourself performing the crop etc once, then run the recording on all the files you want. If you want to automatically resize the smaller images you would have to do a little scripting.
Irfanview also has a comprehensive image batch processor but might require a bit of experimentation to get the results you want.
ImageMagick let's you run commands in a windows command window. You need to be comfortable with creating Dos batch files.
For an example see the last post in this discussion: http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=21112
Relevant example from this forum post:
@echo off
cd C:\Users\user\Desktop\New\New folder
convert *.jpg -fuzz 10%% -trim -write %%02d_trim.png -scale "x1!" txt:
convert *_trim.png -crop 209x329+0+0 -fuzz 10%% -trim +repage %%02d_left.png
convert *_trim.png -crop 173x336+227+0 -fuzz 10%% -trim +repage %%02d_right.png
@pause
-
\$\begingroup\$ Its best if the relevant parts of external resources are quoted or summarized here. External links can potentially go offline at any time, invalidating an answer that just contains a link. The link you provided has an answer, however I'd ask that you quote the relevant command here in your answer to make it more viable. \$\endgroup\$– jristaCommented Sep 13, 2012 at 1:17
First I thought you wanted batch resize, which many programs can do. But then I realized you want to do a combination of resizing and cropping, and you want the computer to calculate how to best cut out 600x600 pixels from the image dynamically.
It is because it is not a "one true solution" kind of task, as it is usually human judgement call, how to crop the image, so it can only be done by bootstrapping certain conditions. For example, look at aspect ratio, and always resize the shortest dimension to X and crop Y (centered/right/left) pixels. If I read your statement right, you want to crop 600 pixels from X and Y centered in both dimensions, if both dimensions are 600 or more. And only resize to 600 if one dimension is smaller than 600?
I've long wanted to add a feature like this to my program "Image View Plus More", and I guess the feature settings should be something like: - crop size: w x h - align width: center/left/right - align height: center/left/right - resize: no/if smaller than/if bigger than/both
Any more settings you'd need?
Update: I am now done programming this feature into Image View Plus More 2.4:
http://www.sequoiagrove.dk/tools.php
How-to: install, drag'n'drop the images you want to crop into it, "save all to new folder", and give it a basename or % to use the original filename, and then in the next dialog select "autocrop" and fill the boxes for width and height, and select alignment "center" for height and width, and check "resize if smaller".
I made a tutorial how to do it:
The solution to the OP problem: http://www.youtube.com/watch?v=wBc1s6zuDJM
Another example: http://www.youtube.com/watch?v=3nFrnaefsqA
-
\$\begingroup\$ See my answer, I wrote out the code in python. \$\endgroup\$– OnlyjusCommented Sep 12, 2012 at 19:17
-
1\$\begingroup\$ Yes now it is not so static, but are you sure the OP is interested in programming his image editing? \$\endgroup\$ Commented Sep 12, 2012 at 20:41
-
\$\begingroup\$ I have no idea. The OP just asked for a program, so I wrote one. \$\endgroup\$– OnlyjusCommented Sep 12, 2012 at 20:52
-
\$\begingroup\$ As you see I now added the feature, and I have ideas for improvements, like "show by example" (on the currently viewed photo), so you cant have to limit yourself to centered or aligned to the edges. Ofc I'd have to figure out how to generalise that example to different aspect ratios and sizes. \$\endgroup\$ Commented Sep 13, 2012 at 7:05
-
\$\begingroup\$ Nice! What is your program written in and is the source available? \$\endgroup\$– OnlyjusCommented Sep 13, 2012 at 12:02
If you like programing, you can use Python (computer language) and an excellent library know has PIL to crop, re-size, plot histograms, get individual pixel vales, etc... on a programmatic level. Thus you can easily write a simple script to find all images in a folder and perform the operation.
This code should do exactly what you want and should process a couple pictures per second, depending on the image size:
#Python 2.7, PIL 1.1.7
import Image
import glob
import os
#Function to resize image, preserving aspect ratio
def resizeAspect(im, size):
w,h = im.size
aspect=min(size[0]/float(w), size[1]/float(h))
return im.resize((int(w*aspect),int(h*aspect)),Image.ANTIALIAS)
imgList=glob.glob('C:/icons/*.png') #Find all png images in a directory
for img in imgList: #Loop through all found images
im = Image.open(img) #open the image
print "resizing:",os.path.basename(img)
w,h = im.size #Get image width and height
if min(w,h)<600: #Check if either dimension is smaller then 600
im=resizeAspect(im,(600,600)) #Re-size Image
w,h = im.size #update image size
center = [int(w/2.0),int(h/2.0)] #Calculate Center
box = (center[0]-300, center[1]-300, center[0]+300, center[1]+300) #Defines a box where you want it to be cropped
croppedIm = im.crop(box) #Crop the image
#croppedIm.show() #Show the cropped image
fileName, fileExtension=os.path.splitext(img)
croppedIm.save(fileName+'_crop.png', "PNG") #Save the cropped image
When you start working on the programmatic level, then the sky is the limit! It is even possible to detect faces and crop around the face, allowing you to intelligently crop thousands of photos...
[updated 09/12/2012]
ThumbsPlus can do what you request. On the Image menu, select Batch Process or press F12 and answer the interactive prompts. You can add multiple operations to a set and save it for immediate use as well as future use. In the future, just access the set name you previously configured to automatically run it on a directory or selection of photos, or even an entire directory tree.
When building the set, you are provided a sample picture to illustrate the option you have added to the operations.
Be careful in building the set, since the order of operations is important.
Sizzlepig.com is an online tool that will do this easily, you can set the "blueprint" size to be 600x600, and then have it crop center all the images.
For the part "For images that are smaller than 600x600 I'd like the program to increase the size of the image to that dimension." I'd highly recommend NOT attempting to upscale the images, but trying to find a higher quality source to work with. I know it's not always possible, but it will result in a much higher quality output than attempting to upscale.
(I work for sizzlepig, but its still a great tool)
-
-
1\$\begingroup\$ Cool. Welcome to the site, and stay around and answer and ask some other questions. :) \$\endgroup\$– mattdmCommented Nov 16, 2012 at 18:43
Irfanview can do this but takes a bit of setting up.
Use the Batch conversion option. Choose "PNG" as your output format. Click on the "options" button next to the output format and choose the compression that you want and click OK
Tick the box that says "Use advanced option" then click the "advanced" button
You'll see this window
Set up the resize with shortest side 600. Make sure you tick "preserve aspect ratio" and "use resample function". Untick "Don't enlarge smaller images"
If you are dramatically reducing the size of your original images then you may want to tick the "sharpen" box and add a value. My requirement was for images of 150x150 size and I found they needed a sharpen value of about 20 to match the quality of image I was getting from photoshop. For your 600x600 images you may not need a sharpen value - so you can untick that option.
Instead of using "crop" use the "canvas size" setting - make sure you tick the option
Click on the "settings" button next to the canvas size option. You'll see this window
Select method 2 and width and height as 600. Choose the "center" option for the anchor
The canvas colour doesn't matter as it won't actually add an image border
Now on the advanced screen again tick the box next to "custom processing order" and make sure that the "resize" is first on the list - i.e. so that the resize is done before the crop.
Click OK
Make sure you've selected the files you want to convert, set up the output directory and then click on "start batch"
Irfanview can do what you are asking for. Its batch mode has a lot of options.
Here is a small tutorial link: http://gd.tuwien.ac.at/graphics/irfantut/batchcon.html
Look for Phatch (Linux, Mac, Windows), it's exactly what you are looking for : http://photobatch.stani.be/download/index.html
There is a utility with multiple options available at http://pixresizer.software.informer.com/
This is good software. Good means, easy to use and faster in work. As I do photography, I am using it to process images in batch. Many times I need to reduce the size of pics to share them over the internet. I also tried some other software too, but found this one good. (I am not associated with this company.)
-
\$\begingroup\$ Is the software any good? Why? Are you associated with the company? \$\endgroup\$ Commented Jul 26, 2013 at 11:37
-
\$\begingroup\$ Hi Paul, Yes this is good software. Good means, easy to use and faster in work. As I do photography, I am using it to process images in batch. I also tried some other software too, but found it good. No!, I am not associated with this company. \$\endgroup\$ Commented Jul 26, 2013 at 12:01
-
\$\begingroup\$ Mahesh, can you take your comments and edit your answer? Not everybody reads the comments. And tell us more and more about it, we'd love to know! \$\endgroup\$ Commented Jul 26, 2013 at 13:27
I don't know why nobody mention it, but my favorite is multipleimageresizer.net. It lets you do a lot like cropping, changing format, size, adding text, watermark...etc. on multiple images at the same time.
This is a real time saver.. I recommend !