Object written by Tim Hatch (vbq at myrealbox dot com)
(c)2001 Tim Hatch
Freeware for noncommercial and Lego site use (email me for commercial license info).
The soruce code for software is available upon request.
THIS LIBRARY REQUIRES VB6 RUNTIMES. You may download the RT installer from
If this does not work for your platform (assuming it's Windows) contact me and I'll
search the knowledgebase for you.
Read the license (you need to "agree" also) and unzip ijl10.dll to /winnt/system32.
Copy the Jpeglib.dll (which is an ActiveX component) to /winnt/system32 also
Run Regsvr32 on jpeglib.dll file to get the RegKeys installed.
NOTE: regsvr32 is located in system/system32. If you have no regsvr32,
please try regsvr.exe. The command line (in a command prompt in /winnt/system32 is
You should then get a "register successful" type of message (or at least no error
That's it for the install. Then, in your script, use this syntax:
Set J = CreateObject("JpegLib.cJpeg")
if J.Width > 0 then
'File loaded correctly
Set J = Nothing
All Errors are suppressed, please use Width or Height, in addition to return values,
to determine if the operation completed correctly.
Please report any bugs to the email address at the top. Also email that address to
be added to the bugfix list (please include [JpegLib] in the subject line).
This library cannot be used with PHP. Please use GD (freely available under the GPL)
for this purpose.
To verify the install worked correctly, please run testlib.exe and follow its instructions.
Run regsvr32.exe /u dllname.dll
Public Function Load(ByVal Fname As Variant) As Variant
Checks to see if the rightmost character of Fname is "g", if so, opens as a jpeg file.
Otherwise, tries to use GIF, BMP, WMF library. When loading GIFs, returns width.
Returns nonzero (width) on success for GIFs, zero on success for Jpegs (feature.
Not a bug). If Jpeg load returns a negative number, it is an error-code. Possible
-1: Failed to load JPEG. File not found or bad permissions. Or something else.
This is the "generic cannot load image" error.
-2: Cannot read JPEG data from file. Invalid or unkonwn format. File opened
successfully, but no useful data was retrived from it.
-4: Failed to init IJL lib. The ijl10.dll was not loaded (for example, did not exist in
winnt/system32; system out of memory/stack; wrong version; or corrupt DLL)
NOTE TO DEVELOPERS: Error codes returned are nonstandard with the ones mentioned
in the IJL enum. The original error-codes were returned only by the ijl_load DLL
call. Uncomment the msgbox lines to return to non-quiet operation.
Public Function SaveModified(ByVal Width As Variant, ByVal Height As Variant, ByVal _
filename As Variant, ByVal qual As Variant) As Variant
This forces a save as a jpeg file, compression and dimensions set at runtime. If
height is 0, autocompute. If you want to vary the width, keeping height constant,
query parameters below, and give this function the dimensions. To get the img
height and width tags, compute at runtime by querying params, below.
If you wish to enlarge the image, you may do so, but it won't look pretty. Please do
not use 0 for the Width parameter, as this may cause the computer to hang (or at
least not do anything useful). This is a guarranted runtime-error-or-corrupt-file.
When saving files, do ensure that the destination file does not exist! If it does,
the binary write will overlap, causing strange things to happen if the new file
is smaller (in byte size).
Public Property Get Height() As Variant
Height, in pixels, of image. If no image loaded, returns 0.
Public Property Get Width() As Variant
Width, in pixels, of image. If no image loaded, returns 0.
Public Property Get ByteSize() As Variant
Image size, in bytes. Useful for determining savings in size old/new. For example,
create thumb using lib, querying "before" size. Then, set object=nothing and
recreate. Open the new thumbnail and query size. If the new one is larger than
the old one, just use the old one as the image, but keep the size tags from the
thumbnail (in proportion).
This class uses a dibsection when loading image. At least one GDI handle will be in use when an
image is loaded. Loading GIFs will require use of approximately three extra temp
handles, and will be considerably slower. They will save at the same speed,
however, because the slowness is in loading using VB-native objects.
Any troubles, just email me.
updates on http://vbq1.tripod.com/