Click here to Skip to main content
13,248,295 members (36,796 online)
Click here to Skip to main content
Add your own
alternative version


136 bookmarked
Posted 22 Sep 2004

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.

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
Member 1022520316-Sep-13 3:31
memberMember 1022520316-Sep-13 3:31 
Questionsuperb Pin
george nepolian5-Mar-12 0:35
membergeorge nepolian5-Mar-12 0:35 
GeneralMy vote of 5 Pin
manoj kumar choubey21-Feb-12 23:06
membermanoj kumar choubey21-Feb-12 23:06 
GeneralReally useful! Pin
Al-Benj7-Dec-11 6:56
memberAl-Benj7-Dec-11 6:56 
GeneralExcellent..! Pin
jdpatel02323-Nov-11 21:51
memberjdpatel02323-Nov-11 21:51 
GeneralMy vote of 5 Pin
ankitj3120-Jul-11 6:08
memberankitj3120-Jul-11 6:08 
GeneralThank you! Pin
AKB6-Mar-11 12:45
memberAKB6-Mar-11 12:45 
QuestionRecurse sub-directories? Pin
robbie19731-Aug-10 1:54
memberrobbie19731-Aug-10 1:54 
AnswerRe: Recurse sub-directories? Pin
Alberto Venditti3-Aug-10 6:34
memberAlberto Venditti3-Aug-10 6:34 
GeneralRe: Recurse sub-directories? Pin
robbie19733-Aug-14 3:50
memberrobbie19733-Aug-14 3:50 
GeneralThanks Pin
hardikdarji19-Feb-10 4:24
memberhardikdarji19-Feb-10 4:24 
GeneralNeed Documentation Pin
Abdul Zamrood11-Jan-10 10:20
memberAbdul Zamrood11-Jan-10 10:20 
GeneralRe: Need Documentation Pin
Alberto Venditti11-Jan-10 21:48
memberAlberto Venditti11-Jan-10 21:48 
GeneralRe: Need Documentation Pin
Abdul Zamrood11-Jan-10 23:17
memberAbdul Zamrood11-Jan-10 23:17 
Generalproportions Pin
mardav11130-Jun-09 6:59
membermardav11130-Jun-09 6:59 
GeneralRe: proportions Pin
Alberto Venditti30-Jun-09 23:26
memberAlberto Venditti30-Jun-09 23:26 
GeneralRe: proportions Pin
mardav1111-Jul-09 10:04
membermardav1111-Jul-09 10:04 
GeneralRe: proportions Pin
Alberto Venditti1-Jul-09 23:04
memberAlberto Venditti1-Jul-09 23:04 
Generalout of memory Pin
sisprog28-Apr-09 12:05
membersisprog28-Apr-09 12:05 
GeneralRe: out of memory Pin
Alberto Venditti29-Apr-09 0:32
memberAlberto Venditti29-Apr-09 0:32 
Was that image inside a batch of lots of big images? If yes, you could try to run the Resizer on a smaller batch containing (eventually only) that specific picture. If the issue doesn't persist, then it was probably due to some missing disposing of Bitmap resources.
Currently, in order to show the resizing in progress, the tool shows in picPhoto.Image the image currently being processed. It should be disposed just before it is discarded by the next one in this line:
picPhoto.Image = img

GeneralRe: out of memory Pin
sisprog29-Apr-09 3:46
membersisprog29-Apr-09 3:46 
GeneralRe: out of memory Pin
Alberto Venditti29-Apr-09 22:07
memberAlberto Venditti29-Apr-09 22:07 
QuestionFfull?? [modified] Pin
juunas22112-Jul-08 5:59
memberjuunas22112-Jul-08 5:59 
AnswerRe: Ffull?? Pin
Alberto Venditti2-Jul-08 6:35
memberAlberto Venditti2-Jul-08 6:35 
GeneralSimilar half-picture as luckydyno was having... Pin
buffbuh12-Jun-08 20:53
memberbuffbuh12-Jun-08 20:53 
GeneralRe: Similar half-picture as luckydyno was having... Pin
Alberto Venditti12-Jun-08 22:56
memberAlberto Venditti12-Jun-08 22:56 
GeneralGood idea - very small "improvement" Pin
plouvou21-May-08 1:52
memberplouvou21-May-08 1:52 
Generalcouldn't scroll down to select an item flowlayout panel Pin
Member 27663242-May-08 12:25
memberMember 27663242-May-08 12:25 
QuestionSize difference on web page Pin
wlanier228-Nov-07 17:22
memberwlanier228-Nov-07 17:22 
AnswerRe: Size difference on web page Pin
Alberto Venditti29-Nov-07 5:56
memberAlberto Venditti29-Nov-07 5:56 
GeneralRe: Size difference on web page Pin
wlanier23-Dec-07 16:43
memberwlanier23-Dec-07 16:43 
GeneralThanks Pin
Jim Franklin10-Dec-06 7:27
memberJim Franklin10-Dec-06 7:27 
GeneralRe: Thanks Pin
Alberto Venditti12-Dec-06 0:05
memberAlberto Venditti12-Dec-06 0:05 
GeneralRe: Thanks Pin
acord12-Dec-06 10:30
memberacord12-Dec-06 10:30 
QuestionResize snippet question Pin
Zayets8-Nov-06 19:37
memberZayets8-Nov-06 19:37 
AnswerRe: Resize snippet question Pin
Alberto Venditti10-Nov-06 5:30
memberAlberto Venditti10-Nov-06 5:30 
GeneralRe: Resize snippet question Pin
Zayets22-Nov-06 19:29
memberZayets22-Nov-06 19:29 
GeneralRe: Resize snippet question Pin
Alberto Venditti23-Nov-06 0:56
memberAlberto Venditti23-Nov-06 0:56 
GeneralThank you Pin
Shailen Sukul19-Aug-06 16:09
memberShailen Sukul19-Aug-06 16:09 
QuestionSource DataStream is corrupt Pin
luckydyno8-Aug-06 20:16
memberluckydyno8-Aug-06 20:16 
AnswerRe: Source DataStream is corrupt Pin
Alberto Venditti9-Aug-06 3:19
memberAlberto Venditti9-Aug-06 3:19 
GeneralGood Job Pin
Tebby6-Apr-06 1:46
memberTebby6-Apr-06 1:46 
QuestionResize with Resampling, for better quality? Pin
Mr_Analogy1-Feb-06 21:40
memberMr_Analogy1-Feb-06 21:40 
AnswerRe: Resize with Resampling, for better quality? Pin
Alberto Venditti3-Feb-06 3:29
memberAlberto Venditti3-Feb-06 3:29 
GeneralResize pdf files Pin
Triskal17-May-05 9:30
memberTriskal17-May-05 9:30 
GeneralRe: Resize pdf files Pin
Alberto Venditti17-May-05 10:47
memberAlberto Venditti17-May-05 10:47 
GeneralRe: Resize pdf files Pin
preetraj17-Jul-06 22:36
memberpreetraj17-Jul-06 22:36 
GeneralRe: Resize pdf files Pin
preetraj17-Jul-06 22:30
memberpreetraj17-Jul-06 22:30 
GeneralAsk for GIS software Pin
nobita3x13-Mar-05 17:11
membernobita3x13-Mar-05 17:11 
GeneralRe: Ask for GIS software Pin
Alberto Venditti14-Mar-05 8:21
memberAlberto Venditti14-Mar-05 8:21 

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

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

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