Click here to Skip to main content
Click here to Skip to main content

Image Batch Resizer

, 26 Sep 2004
Rate this:
Please Sign up or sign in to vote.
A simple utility to quickly resize images


I came back from my holidays, with tons of photos taken with my new digital camera. Normally, I prefer to take pictures using the best quality and resolution, and this - of course - implies having bigger files to manage.

Often, at a good resolution, a single photo in JPG format takes more than 1 Mb, and this is not so comfortable if you want to send your pictures to your friends via email, or to put them on a web site. You have to reduce the quality of your pictures, resampling them at a lower resolution.

I had this need of resizing pictures and - even if the world is full of image processing software capable of doing that - I decided to write my little piece of code to do it in VB.NET.

How the utility works

The utility I wrote is very simple: given an "input" folder, it looks for JPG pictures in that folder and - one by one - it takes them, reduces their sizes by a specified factor, and save them in a given "output" folder.

Image Batch Resizer user interface

In the "normal mode", when you press the "GO" button, the input folder is scanned, each single picture found is shown in the preview box and you are asked about the conversion of that specific picture. Under the preview box you can find the filename and the size of the image (size on disk, dimensions X and Y, aspect ratio).

The conversion can be done also in "batch mode" (that is: without human intervention, converting all the pictures found in the input folder) if you check the "Batch processing" checkbox before pressing the "GO" button. To stop the batch processing while running, just uncheck the option to revert to "normal mode".

Something about the code

The core reducing functionality is inside the Reduce() subroutine, specifically in this line of code:

img = New Bitmap(img, New Size(img.Size.Width * factor, 
  img.Size.Height * factor))

Notice that the reducing factor is applied to both picture dimensions (to preserve the aspect ratio); so, if the original picture's size is [x,y] and the reducing factor is F, the resulting image is sized [x*F,y*F] (hence its area is reduced by F*F).

It's easy to modify this formula to obtain different resizing behaviors. For example, if the set of the original pictures is not homogeneous in the sizes, you could want to reduce them not by a fixed factor, but to a specified size (regardless the original size).

The Reduce() subroutine also contains some lines of code used to compute the file size of the resulting JPG picture. This computation is simply done looking at the size of a MemoryStream on which the image is saved in JPG format:

Dim SizeKb As String
Dim ms As New MemoryStream()
img.Save(ms, Imaging.ImageFormat.Jpeg)
SizeKb = (ms.Length \ 1024).ToString() & "Kb "

A last thing to notice in the Image Batch Resizer utility is the persistence of the configuration settings between working sessions, accomplished by the use of the ConfigOpt class (described in a previous article of mine).


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Alberto Venditti
Technical Lead
Italy Italy
I was born in 1970.
My first computer experience dates back to early 80s, with a Sinclair ZX81.
From that time on, as many "friends" say, my IT-illness has increased year by year.
I graduated in Electronic Engineering and earned the following Microsoft certifications:
MCP, MCT, MCDBA, MCSD, MCAD, MCSD for .NET (early achiever).
I worked in IT as a developer, a teacher, a consultant, a technical writer, a technical leader.
IT knowledge applied to real life is my primary interest and focus.

Comments and Discussions

GeneralRe: Need Documentation PinmemberAlberto Venditti11-Jan-10 21:48 
GeneralRe: Need Documentation PinmemberAbdul Zamrood11-Jan-10 23:17 
Generalproportions Pinmembermardav11130-Jun-09 6:59 
GeneralRe: proportions PinmemberAlberto Venditti30-Jun-09 23:26 
In order to set a specific height for resulting images (while mantaining the original aspect ratio), you basically have to modify the Reduce() subroutine.
Currently, this procedure receives a reducing factor and applies it to Height/Width of output images:
img = New Bitmap(img, New Size(img.Size.Width * factor, img.Size.Height * factor))
If you could supply a fixed "height" instead of a "factor", you could write:
img = New Bitmap(img, New Size(img.Size.Width * (height / img.Size.Height), height))
(that is: your reducing factor is now the ratio between the target haight and the original height)
So, if you want to minimize the modification to the code, you could:
- consider the "factor" variable and the txtRedFactor textbox actually as the image target height;
- rename the label for the txtRedFactor so that the user understand it *is* the image target height
- change this line:
img = New Bitmap(img, New Size(img.Size.Width * factor, img.Size.Height * factor))
img = New Bitmap(img, New Size(img.Size.Width * (factor / img.Size.Height), factor))
Hope this helps (and this works, because I did't try it directly... Smile | :) ).
Cheers, AV
GeneralRe: proportions Pinmembermardav1111-Jul-09 10:04 
GeneralRe: proportions PinmemberAlberto Venditti1-Jul-09 23:04 
Generalout of memory Pinmembersisprog28-Apr-09 12:05 
GeneralRe: out of memory PinmemberAlberto Venditti29-Apr-09 0:32 
GeneralRe: out of memory Pinmembersisprog29-Apr-09 3:46 
GeneralRe: out of memory PinmemberAlberto Venditti29-Apr-09 22:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150123.1 | Last Updated 27 Sep 2004
Article Copyright 2004 by Alberto Venditti
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid