Persits Software, Inc. Knowledge Base Articles

HOWTO: Create thumbnail of a remote image from a URL

Problem Summary

AspJpeg can only open an image for resizing from a physical path, not a URL. This article explains how to circumvent this limitation using a Microsoft XML DOM object.

Solution

For AspJpeg to open a remote image located at a particular URL, this image must first be downloaded to the server where AspJpeg is running. To perform the download, Microsoft XML DOC's XMLHTTP object can be used.

The XMLHTTP object enables you to specify a URL to download the image from, and perform the download to a memory array, which can then be passed directly to AspJpeg's OpenBinary method. This frees your application from the necessity to create a temporary file on the server's hard drive.

The following code snippet demonstrates this technique:

Set objHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.Open "GET", "http://www.aspjpeg.com/images/ps_logo.gif"
objHTTP.Send

Set Jpeg = Server.CreateObject("Persits.Jpeg")
Jpeg.OpenBinary(objHTTP.responseBody)

Jpeg.Height = jpeg.OriginalHeight / 2
Jpeg.Width = jpeg.OriginalWidth / 2
Jpeg.Save "c:\path\thumb.jpg"