Click here to Skip to main content
Licence 
First Posted 22 Sep 2004
Views 188,056
Bookmarked 129 times

Image Batch Resizer

By | 26 Sep 2004 | Article
A simple utility to quickly resize images

Introduction

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).

License

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

Member

I was born in 1970.
 
I studied Electronic Engineering (graduated in 1997).
 
Subsequently, I passed some Microsoft exams, and currently I'm certified as:
MCP, MCT, MCDBA, MCSD, MCAD, MCSD for .NET (early achiever).
 
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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralRe: out of memory PinmemberAlberto Venditti21:07 29 Apr '09  
QuestionFfull?? [modified] Pinmemberjuunas22114:59 2 Jul '08  
AnswerRe: Ffull?? PinmemberAlberto Venditti5:35 2 Jul '08  
GeneralSimilar half-picture as luckydyno was having... Pinmemberbuffbuh19:53 12 Jun '08  
GeneralRe: Similar half-picture as luckydyno was having... PinmemberAlberto Venditti21:56 12 Jun '08  
GeneralGood idea - very small "improvement" Pinmemberplouvou0:52 21 May '08  
Generalcouldn't scroll down to select an item flowlayout panel PinmemberMember 276632411:25 2 May '08  
Hi,
 
this is regarding a vb.net windows application for developing a picasa like image viewer, i have a created a user control with one checkbox, picturebox and a textbox grouped inside a panel. In another form i have placed a flowlayout panel. when the user select a folder from the browse menu, the program will find all the .jpeg images from that folder and to show it as thumbnail, the program will dynamically add the usercontrol to the flowlayout panel. i have done this much, but the problem what i am facing now is, if we scroll down the flowlayoutpanel to the bottom and try to select a usercontrol then automaticaly flowlayoutpanel's scrollbar will go to top. so i cannot select an item by scrolling the panel, i can select the item which is shown at the top 2-3 lines, for selecting rest of the pictures, i need to scroll down. but if i click any of the item other than the top 2-3 levels, then the scrollbar will reset to top.
 
can i anyone help me to resolve this problem???
 
Thanks
~Jay
QuestionSize difference on web page Pinmemberwlanier216:22 28 Nov '07  
AnswerRe: Size difference on web page PinmemberAlberto Venditti4:56 29 Nov '07  
GeneralRe: Size difference on web page Pinmemberwlanier215:43 3 Dec '07  
GeneralThanks PinmemberJim Franklin6:27 10 Dec '06  
GeneralRe: Thanks PinmemberAlberto Venditti23:05 11 Dec '06  
GeneralRe: Thanks Pinmemberacord9:30 12 Dec '06  
QuestionResize snippet question PinmemberZayets18:37 8 Nov '06  
AnswerRe: Resize snippet question PinmemberAlberto Venditti4:30 10 Nov '06  
GeneralRe: Resize snippet question PinmemberZayets18:29 22 Nov '06  
GeneralRe: Resize snippet question PinmemberAlberto Venditti23:56 22 Nov '06  
GeneralThank you PinmemberShailen Sukul15:09 19 Aug '06  
QuestionSource DataStream is corrupt Pinmemberluckydyno19:16 8 Aug '06  
AnswerRe: Source DataStream is corrupt PinmemberAlberto Venditti2:19 9 Aug '06  
GeneralGood Job PinmemberTebby0:46 6 Apr '06  
QuestionResize with Resampling, for better quality? PinmemberMr_Analogy20:40 1 Feb '06  
AnswerRe: Resize with Resampling, for better quality? PinmemberAlberto Venditti2:29 3 Feb '06  
GeneralResize pdf files PinmemberTriskal8:30 17 May '05  
GeneralRe: Resize pdf files PinmemberAlberto Venditti9:47 17 May '05  

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.

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