Click here to Skip to main content
15,891,204 members
Articles / Programming Languages / C#
Article

Thumbnail Generator - An easy way to process thumbnails from a large amount of images

Rate me:
Please Sign up or sign in to vote.
4.85/5 (15 votes)
9 Mar 20031 min read 321.9K   5.3K   88   20
Thumbnail Generator application supporting a bunch of image file types (for both: source images and target thumbnails), fixed target image size as well as ratio calculation, and full internationalization.

Sample Image - ThumbGenerator/ThumbGenerator.png

Introduction

I have always had problems generating thumbnails from a large amount of images quickly and easily. Also standard graphic programs couldn't meet my needs - or it simply took too much time handling image after image.

Benefits

This Thumbnail Generator is qualified for generating thumbnails of images you are publishing on the Internet. Pre-generated thumbnails save you processor utilization and disk space (if you're generating thumbnails on the fly) - or user's time and money.

But also converting a large amount of images from one file format to another can be handled easily.

This project might also be an interesting starting point for Win Form rookies. Learn how forms, simple internationalization support and XML are working together! Just download the project source code, all source files are commented.

Supports

Image support

  • Different file formats (BMP, GIF, JPEG, PNG, TIFF) - for both: source images and target thumbnails
  • Self specified thumbnail image extensions
  • Preview of source images and output thumbnails (including information on width, height, ratio)
  • Fixed width, height as well as maintaining aspect ratio
  • Bilinear re-sampling

Generating a ListBox item:

C#
/* Retrieve image to get it's infos */
Image LbxSourceImage = Image.FromFile(filesFromDialog[i]);
imgList.Images.Add(LbxSourceImage);


/* Calculate image ratio */
float Ratio=((float)LbxSourceImage.Width)/((float)LbxSourceImage.Height); 

/* Generates Listboxitem */
ImageListBoxItem lbxItem = new ImageListBoxItem(
    filesFromDialog[i].ToString()+                /* Filename */
    "\r\n"+txtWidth+LbxSourceImage.Width.ToString()+    /* Width    */
    ", "+txtHeight+LbxSourceImage.Height.ToString()+    /* Height   */
    ", "+txtRatio+Ratio.ToString(),i);            /* Ratio    */

lbxSource.Items.Add(lbxItem);

Multilingual support

Also full multilingual support for English and German language is provided. (Feel free to contribute other translations ;) )

Internationalization is managed via XML. All GUI texts are read on startup, from the application configuration file (of course the language can also be changed during a session). The project includes a collection of useful methods for processing XML documents. You can easily use them for your own applications.

The configuration file looks like:

XML
<?xml version="1.0" encoding="UTF-16"?>
<!DOCTYPE Application SYSTEM "Config.dtd">
<Application>
  <Information>
    <Name>Thumbnail Generator</Name>
    <Version>0.8</Version>
  </Information>
  <StdLanguage Type="en"/>
  <Language Type="en">
    <Text GUIRelation="btnGenerateThumb">Generate Thumbnails --></Text>
    <Text GUIRelation="gbxSource">Source:</Text>

...

  </Language>
  <Language Type="de">
    <Text GUIRelation="btnGenerateThumb">Generiere Thumbnails --></Text>
    <Text GUIRelation="gbxSource">Quelle:</Text>
    <Text GUIRelation="gbxTarget">Ziel:</Text>

...

  </Language>
</Application>

Within the application the language information is fetched via XPath. Sample calls:

C#
XPathDocument XPathDoc = new XPathDocument(configFileName);
XPathNavigator nav     = XPathDoc.CreateNavigator();

gbxSource.Text = XmlManager.GetValueFromXPath(nav, 
          "/Application/Language[@Type='"+
          CurrentLang+"']/Text[@GUIRelation='gbxSource']");
gbxTarget.Text = XmlManager.GetValueFromXPath(nav, 
          "/Application/Language[@Type='"+
          CurrentLang+"']/Text[@GUIRelation='gbxTarget']");

History

  • 09. March 2003: Initial release. See section "Supports"

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


Written By
Web Developer
Germany Germany
Experience:
- Java
- C#
- XML, XSL, PHP, ASP, ASP.NET
- Server administration

- ASM, Visual Basic (poor)
- Linux (poor)

If you have any offers, questions, or project ideas please feel free to contact me.

If you experience any bugs in my software, please report them.

Thank you.

Comments and Discussions

 
GeneralSmall error in your demo with Maintain aspect with height specified Pin
maildlee31-Jan-10 19:46
maildlee31-Jan-10 19:46 
Generalsending the Image to another function Pin
dogmatic697-Nov-07 2:43
dogmatic697-Nov-07 2:43 
GeneralHere's the spanish translation and some comments Pin
bauersachs11-Dec-06 3:08
bauersachs11-Dec-06 3:08 
I cannot reach the author, it looks like his email isn't valid anymore. I've written him the following email (that bounced back). I'll post it here just in case someone else would like to have these infos too or in case he reads here again.

I've translated the texts of Thumbnail Generator 0.8 into spanish (see below). It's not my native language and the translations are therefore not perfect.

Some bugs in the tool I've noticed:
- When turning off and reenabling "maintaion radio" checkbox both size fields are deactivated. After switching width / height it's ok.
- In the deactivated width and height field there is written "ratio". If the language will be changed the text there doesn't refresh, only after a manual refresh.
- I've set the height fix and enabled "maintain ratio" and made a test. All pics have been squeezed in width. Probably a bug somewhere exchanging width and height.

Suggestions for future enhancements:
- Because frequently the pics are rotated already, it should be possible to set the settings for horizontal pics (width>height) and for vertical pics (height>width) separately.
- I would need something to reduce the pics to a special format, but without changing the ratio, but instead use a little cropping. For example original pics in the format 302:200 and 598:400 should both be converted to 30:20 pixel while cutting off some pixel at the border during the resizing.
- Support for NEF pics (Nikon D2X)
- Don't show pics in the listboxes (takes too long), perhaps optional
- Setting the compression ratio for JPG files or setting a destination file size
- Filename jpg instead of jpeg

But the sourcecode is good for me and I'll be able to do something with it. Thank you.

Greetings from Switzerland

Eric

---
<Language Type="es">
<Text GUIRelation="btnGenerateThumb">Generando Thumbnails --&gt;</Text>
<Text GUIRelation="gbxSource">Origen:</Text>
<Text GUIRelation="gbxTarget">Destino:</Text>
<Text GUIRelation="gbxSettings">Opciones del thumbnail:</Text>
<Text GUIRelation="lblExtension">Añadido del archivo:</Text>
<Text GUIRelation="lblFormat">Formato del imagen:</Text>
<Text GUIRelation="cbxRatio">Tamaño en relativo a:</Text>
<Text GUIRelation="rdbWidth">Ancho</Text>
<Text GUIRelation="rdbHeight">Altura</Text>
<Text GUIRelation="lblWidth">Ancho:</Text>
<Text GUIRelation="lblHeight">Altura:</Text>
<Text GUIRelation="lblPixel">Pixel</Text>
<Text GUIRelation="miFile">Archivo</Text>
<Text GUIRelation="miChooseDir">Elige imágenes...</Text>
<Text GUIRelation="miGenThumbs">Generar Thumbnails</Text>
<Text GUIRelation="miFileClear">Vaciar lista de los archivos</Text>
<Text GUIRelation="miPreferences">Opciones...</Text>
<Text GUIRelation="miExit">Terminar</Text>
<Text GUIRelation="miHelp">Ayuda</Text>
<Text GUIRelation="miInfo">Informaciones</Text>
<Text GUIRelation="btnOK">OK</Text>
<Text GUIRelation="btnCancel">Cancelar</Text>
<Text GUIRelation="gbxLang">Opciones de idioma</Text>
<Text GUIRelation="lblLang">Por favor elige su idoma (código ISO):</Text>
<Text GUIRelation="txtWidth">Ancho: </Text>
<Text GUIRelation="txtHeight">Altura: </Text>
<Text GUIRelation="txtRatio">Proporción: </Text>
<Text GUIRelation="txtRatioShort">Proporción</Text>
<Text GUIRelation="errImage">Error generando el imagen: </Text>
<Text GUIRelation="errFile">Thumbnail no podía estar creado. Archivo: </Text>
<Text GUIRelation="errChoose">Por favor elige los imágenes de los cuales usted quiere hacer thumbnails.</Text>
</Language>
---


Eric Bauersachs
Generaldelete files that add to imageList box Pin
nazli28-Aug-06 3:22
nazli28-Aug-06 3:22 
QuestionHELPPPPPPPPPPPPP Pin
seapigg16-Jul-06 6:47
seapigg16-Jul-06 6:47 
Generaluse ratio to make images look better Pin
djohnson1496-Dec-05 2:55
djohnson1496-Dec-05 2:55 
GeneralI-Load - thumbnail generator free component Pin
zioturo3-Nov-05 0:59
zioturo3-Nov-05 0:59 
GeneralA generic error occurred in GDI+ Pin
Paul Novelli9-Jul-05 6:11
Paul Novelli9-Jul-05 6:11 
GeneralRe: A generic error occurred in GDI+ Pin
dogmatic697-Nov-07 2:25
dogmatic697-Nov-07 2:25 
Questionsource of the dll?? Pin
mistery2218-Oct-03 8:51
mistery2218-Oct-03 8:51 
GeneralCannot find file exception Pin
Huang, XiaoTian20-Apr-03 17:48
Huang, XiaoTian20-Apr-03 17:48 
QuestionControls library? Pin
Todd Smith11-Mar-03 4:20
Todd Smith11-Mar-03 4:20 
AnswerRe: Controls library? Pin
perlmunger11-Mar-03 9:53
perlmunger11-Mar-03 9:53 
GeneralRe: Controls library? Pin
Christian Ballerstaller11-Mar-03 10:06
Christian Ballerstaller11-Mar-03 10:06 
Generalirfanview Pin
Wilhelm Berg10-Mar-03 21:28
Wilhelm Berg10-Mar-03 21:28 
GeneralRe: irfanview Pin
Christian Ballerstaller11-Mar-03 10:12
Christian Ballerstaller11-Mar-03 10:12 
GeneralRe: irfanview Pin
jstephenson177122-Jan-04 15:23
jstephenson177122-Jan-04 15:23 
GeneralRe: irfanview Pin
Todd C. Gleason16-Nov-04 13:51
Todd C. Gleason16-Nov-04 13:51 
GeneralRe: irfanview Pin
Rowland Shaw29-Dec-05 3:14
Rowland Shaw29-Dec-05 3:14 
GeneralRe: irfanview Pin
Dermot O S26-Oct-07 1:29
Dermot O S26-Oct-07 1:29 

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.