'This script produces resized and thumbnail images out of a given 'directory on the fly by using imagemagic Option Explicit On Error Resume Next Const ERROR_SUCCESS = 0 Dim img Dim info Dim rs Dim elem Dim sMsgs Dim inputdir Dim inputfld Dim outputdir Dim outputfld Dim fso Dim str Dim f Dim tnSize Dim maxSize inputdir = "C:\temp\input\" outputdir = "C:\temp\output\" 'define how big the thumbnail should be tnSize = "20%" 'define the max dimensions for the resized images maxSize = "320x200" Set img = CreateObject("ImageMagickObject.MagickImage.1") Set fso = CreateObject("Scripting.FileSystemObject") Set inputfld = fso.GetFolder(inputdir).Files Set outputfld = fso.GetFolder(outputdir).Files str = "" 'reads all files in input dir, resizes them, creates thumbnails 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 < to change the dimensions of the image only if its width or height exceeds the geometry specification. > 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 < or > 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 If Not fso.fileexists(outputdir & "tn_" & f.Name) Then rs = img.Convert("-thumbnail",tnSize,inputdir & f.Name,outputdir & "tn_" & f.Name) End If If Not fso.fileexists(outputdir & f.Name) Then rs = img.Convert("-resize",maxSize,inputdir & f.Name,outputdir & f.Name) End If Next If Err.Number <> ERROR_SUCCESS Then ShowError: WScript.Quit MsgBox "info: " & msgs Set img=Nothing WScript.Quit(0) Sub ShowError sMsgs = "" If BasicError(Err.Number) > 5000 Then sMsgs = " ImageMagickObject" & vbCrLf End If WScript.Echo Err.Number & ": " & Err.Description & vbCrLf & sMsgs End Sub Function BasicError(e) BasicError = e And &HFFFF& End Function