Net Transport Training Area :: Downloads

Rename Images According Their Canvas Size application

 

[ Language ] :: [ Main Index ] :: [ Site Navigation ] :: [ Tutorials ] :: [ Downloads ] :: [ Contact ]

 

 

At the time, I programmed this util, I have been often looking for concrete images at Temporary Internet Files directory after finishing the internet session. Sometimes I did not remember all file names, or even I did not know them. So I have had to browse through all subdirectories and scanned images with some images viewer in thumbnail mode sorted by file size. It is really boring, I think, because it is not easy and always possible to guess pixel size only by file size. A specially on grayscale only (8-bit) JPEGs as well as PNGs.

When I started to use Opera as browser, I found this program even more useful. Opera does not use an original filenames for cached files on local disk.

I wrote an e-mail to a few freeware and shareware authors with propose to implement a sort by real canvas size of images. All of them answer that this is interesting option. However, all of them also refuse. So, I have programmed this small utility, which use a sort according to file-names at system level.

 

This utility scan selected directory for BMP, GIF, JPEG and PNG files. If found, the canvas size is computed from pixel dimensions and unit. This value can be subtracted from maximum value and filled from left with zero. After join with some “identify string” it is inserted into beginning of file name. You can specify minimum dimensions and minimum file size as well as maximum proportions of sizes (because of banners) to determine which files will be ignored.

By this way, you will have the images sorted according their pixel size. Image with the biggest canvas is in front of list – in case you sort files according their names. When sorted by extension, you found there the biggest image of concrete file format, of course. When values are not subtracted, images are sorted in reverse order. I.e. the biggest canvas is at the end of list.

There is also a button, which will restore back original filenames, so next time can be cache reused.

 

Please note, that you must have privileges for access to hidden and system directories, when you want to modify Temporary Internet Files directory of Microsoft Internet Explorer. It can be set from menu of Control Panel (Tools > Options :: View tab). This application does not use any aggressive techniques to access into this kind of directory. So even when you have this privileges, it is possible, that this util will crash.

Images can be identify not only by extension, but even by their header, so extension is not important. You can do this by switching-on “Identify by header”. This can result in longer proceed, of course. When you additionally switch-off “Suppose normalized header”, all files will be scanned throughout always! Then process will consume a lot of time.

Why it is good for? Well, you can find a JPEG image in your Temporary Internet Files directory, which file name will be download.php?id=122155AFBC01. Or the file will have a few extension, or none, or something totally meaning-less. All browsers recognized images by their header, not by extension!

In future I planned to modify this util with some INI-file capability, where all of supported file formats will be listed and defined. Perhaps, a PCX, TGA and TIFF could be valuable. But I do not believe there is really such need, or purpose. There is also a possibility to put non-displayed information as remark into all of this file types. It can be used for more accurate file-names restoring.

There is an worldwide patent for implementation of LZW compress method used by GIF #4,558,302, which is owned by Unisys. Appropriate rights should finish 2003-06-20 at USA, but probably still be valid at other countries.
GIF header and its extension blocks are not packed. It is the only thing, which is handled by this util – it is read at binary level – according to published GIF87/GIF89a File Format Specification published by owner of GIF service mark, CompuServe Incorporated.


Technical notes:

BMP

Honored extensions are *.bmp, *.rle, and *.dib. Microsoft Windows bitmap header is straight, because of fix file structure. It starts with ‘BM’ strings followed by 4 bytes with file-size. I check them both (from file-size only the last byte, because it is quicker), so there is a small chance that some text, or binary file will be recognized wrongly.

There can be one problem with Device Independent Bitmap for Microsoft Windows 3.x. This has been popular some 10 years ago. It is a kind of RIFF family formats: like WAV, AVI, or Video-CD’s MPEG-I. Sorry, but although I have detailed reference about its inner structure, I have no application which supports this format. So I cannot check it. Generally it starts with ‘RIFF’ (or ‘RIFX’ or rarely ‘XFIR’ when bytes are at Motorola order) followed by 4 bytes of data-length and next is ‘RDIB’ chunk. Header is 40 bytes long all-over. These are really rare presently, because BMP has been transformed to be device independent. So, if file with .dib extension has different structure than bitmap, it is ignored.

In very rare cases – thanks to »Big Blue« IBM and its politics about OS/2 – you can encounter an OS/2 bitmap files. Their header can start with ‘BA’ (bitmap array), ‘CI’ (color icon), ‘CP’ (color pointer, i.e. cursor), ‘IC’ (icon) and ‘PT’ (pointer – usually cursor). These start codes are all honored also.

Once, I encounter with file extension *.lgo, however I do not found any reference, why and by who it has been given. So, I decide to ignore it – this bitmap will be found, if you check “Identify by header” option.


GIF

Honored extension is *.gif. Both versions – i.e. GIF87a and GIF89a – are handled. GIF use also a fix structure of file. It is true at least for position of header. So there should be no problem with misinterpretations: there is no significant chance that any text or binary file will have valid structure.

What about static and animated GIFs? Well, there is no flag or byte informed how many images are really stored inside of file. It can be checked by scanning through all file and counting numbers of all full-size segment draw. However, it consume a lot of time. So, I decide to do it by guessing.

There is one kind of extension block at GIF89a defined, which is called “Graphic Control Extension”. Identify is by two bytes $21F9. There can be set if the input from user is necessary, and / or, the time interval between redraw of canvas. It is obvious, that static GIF will have zero time-interval and probably no action from user will be necessary.

So, as soon as any of these two values is set, I suppose, that GIF is animated. A special char ‘A’ is put at the end of inserted prefix. Static GIFs are marked with ‘S’.


JPEG

Honored extensions are *.jpg, *.jpe, *.jpeg, *.jff, *.jfi, *.jfif. JPEG has no fix inner structure. Only sure thing is the Start of Image marker ($FFD8) on the beginning. After it, there is usually Application APP0 marker ($FFE0), where the string ‘JFIF’ can be found. Canvas size is defined at Start of Frame marker ($FFC0, or $FFC1) which is usually the fifth block in file.

However, presently, it is not always true. Digital cameras, for example, inserts as the first very large EXIF block ($FFE1). Almost all graphic applications add its our header on the beginning. So, it is not rare situation, that JPEG has a few APP0 markers all over the file. Start of Frame can be everywhere also.

I read the first 2 kBy of file when “Suppose normalized header” option is checked. I conclude from my experiences, that at least one APP0 marker and Start of Frame marker will be there. However, it could not. Thankfully, it happens only at very big JPEG files, which can be found easily by sorting the directory according file-size.

If you still have problem, you should switch off normalized header options. But be aware, it will cost you a lot of time and disk has been scanned through-out byte by byte! You can heat up and/or destroy it, in this way!

JPEG2000 (.jp2, .j2k) files are not supported at all. One, because they are multi-resolutional. Two, because I have only two proposal documents from different companies and no final draft. Three, there is really no strict header: even XML entry presence is not necessary, so I have to scan through all binary file and analyze all streams. Four, they can be easily found, after all.


PNG

Honored extensions are *.png, *.mng, *.jng. All three has fix position of identification – for PNG it is: $89, ‘PNG’, $0D0A1A0A – and image header (‘IHDR’). It cannot be accidentally misinterpreted by text file at all, by binary file there is always a small chance.

Multiple-image Network Graphic files are still very, very rare, even that they are supported by all major internet browsers and graphic applications. Usually you meet with animated GIFs, or Macromedia Flash animations. Pity, because it is an ideal format for interactive slide-shows and even simple video-movies with simulations, screen-captures, etc. generated on computer. The same status have MNG-Video and JPEG Network Graphics files.

MNG and JNG file structure are naturally similar to PNG. MNG starts with $8A, ‘MNG’, etc. and its first header is marked by ‘MHDR’. The position of canvas size at this header is the same as on PNG. JNG is image compressed with loss-less JPEG process (it is a kind of compression). File starts with $8B, ‘JNG’ and the first header is ‘JHDR’.

There is no possibility to PNG file be animated – it is a purpose why MNG exists, so I do not add a special char to diversify them. In general, as soon as you saw an MNG extension, you should treat a file as animation.

 

Downloads

You can download utility itself or its source code in Pascal. (214 kBy, resp. 21 kBy)

 

General licence

I am citizen of Slovak republic. According to Slovak law - in concrete Act no. 618 / 2003 (ex. Act no. 34 / 2001) - I have got a copyright automaticly. I do not maintain this site for profit, so I will not demand on "advantages" in case of foreign subjects. Slovakian companies have declared their duties clearly at mentioned act.

I am asking you for only two things: credits and link. Link should be fully vissible, i.e. e.g. http://www.ntta.szm.sk/downloads/. Present time is silly and hectic enough - there is no necessary to make more tension and behave each-other as beast.

It is against my will to use manuals printed or at electronic form - including audio-reading and video-capture - by any corporation as their internal material, without my permission. It is against my will too, to use any of presented original freeware applications by "legal subject" or corporations "en masse". You should contact me, first and tell me at least about your reasons.

diplm. mgr. ing. Marián STACH, MsTSc.
Prešov, Slovakia, Central Europe
2003-07-03