'This script produces resized images out of a given
'directory on the fly by using imagemagick
'This script is compiled by John Zhou, MWH Global, 1/14/2007
'This script is not part of any deliverables of PWP eGIS program currently undertaken by MWH
'This script is given to help PWP resizing large scanned images for free.
'Neither John Zhou, personally or MWH as a company is responsible for any damage caused by using this script.
'PWP should use this script at their own risk and discreetion.
'depending the amount file to be proceessed, it may take minutes to hours to run the script. Be patient.
'Need ImageMagick installed to run the script http://www.imagemagick.org/script/binary-releases.php#windows
Option Explicit 'This is to ensure no variable is used without defintion.
On Error Resume Next
Dim img 'ImageMagick object
Dim inputdir 'original directory
Dim inputfld ' file collection in the original folder
Dim outputdir 'destination directory
Dim outputfld 'file collection in the destination folder
Dim fso 'filesystem object
Dim f 'file object
Dim tnSize 'scale size
Dim nFileSize 'largest file size to be resized
inputdir = "d:\water\" 'This is the directory where the original files/images located
outputdir = "d:\water\"'This is the directory where the resized images will be located
'define how big the thumbnail should be
tnSize = "50%" 'default to reduce 1/4 size of original, it can be changed
nFileSize = 100000000 ' default only file larger than 100 Mega need to be resized
Set img = CreateObject("ImageMagickObject.MagickImage.1") 'Create a ImageMagick Object
Set fso = CreateObject("Scripting.FileSystemObject") 'Create a File System Object
Set inputfld = fso.GetFolder(inputdir).Files 'Get all files in the original folder
Set outputfld = fso.GetFolder(outputdir).Files 'Get all files in the destination folder
'reads all files in input dir, resizes them and copies them into output dir
'OPTIONS FOR CONVERT FUNCTION (taken from http://imagemagick.org/script/command-line-options.php):
'
'-resize width{%}{@} {!} {<} {>}
'resize an image.
'By default, the width and height are maximum values. That is, the image is expanded or contracted to fit the width and height value while maintaining the aspect ratio of the image. Append an exclamation point to the geometry to force the image size to exactly the size you specify. For example, if you specify 640x480! the image width is set to 640 pixels and height to 480.
'If only the width is specified, the width assumes the value and the height is chosen to maintain the aspect ratio of the image. Similarly, if only the height is specified (e.g., -resize x256, the width is chosen to maintain the aspect ratio.
'To specify a percentage width or height instead, append %. The image size is multiplied by the width and height percentages to obtain the final image dimensions. To increase the size of an image, use a value greater than 100 (e.g. 125%). To decrease an image's size, use a percentage less than 100.
'Use @ to specify the maximum area in pixels of an image.
'Use <> resizes the image only if both of its dimensions are less than the geometry specification. For example, if you specify 640x480 and the image size is 256x256, the image size does not change. However, if the image is 512x512 or 1024x1024, it is resized to 480x480. Enclose the geometry specification in quotation marks to prevent the <> from being interpreted by your shell as a file redirection.
'if the -filter option precedes the -resize option, the image is resized with the specified filter.
'If the -support option precedes the -resize option, the image is resized with the specified support.
For Each f In inputfld 'for each file in the original file folder
'if and only if there is no "resized" image in the destination folder (avoid redudant work) and the original file size is larger than nFileSize
If Not fso.fileexists(outputdir & fso.GetBaseName(f) & "_resize." & fso.GetExtensionName(f)) and f.Size > nFileSize Then
' Use ImageMagick's Convert function to resize and add "_resize" at the end of original file name
rs = img.Convert("-quiet","-resize",tnSize,inputdir & f.Name,outputdir & fso.GetBaseName(f) & "_resize." & fso.GetExtensionName(f))
End If
Next
WScript.Echo "Done" 'tell the user the file is done
Set img=Nothing
Thursday, February 21, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment