|
|
|
|
|
|
|
This example shows how to draw a cropped image from a file. In
this instance we're going to discard a 20 pixel border round the
edge of the image.
|
|
|
|
|
|
|
|
|
|
We start by setting up variables we will use later - the path to
the source file and the path to the output file.
[VBScript]
inpath = Server.MapPath("birds.jpg")
outpath = Server.MapPath("croppedbirds.jpg")
|
|
|
|
|
|
|
|
|
|
We will need a few objects so we create them all here for
convenience.
[VBScript]
Set gr = Server.CreateObject("ImageGlue7.Graphic")
Set rc = Server.CreateObject("ImageGlue7.XRect")
Set ca = Server.CreateObject("ImageGlue7.Canvas")
|
|
|
|
|
|
|
|
|
|
We need to find the portion of the image we want to draw. To do
this we get the natural Rectangle of the main image using the
Graphic object. We then inset the Rectangle by 20 pixels on each
side.
[VBScript]
gr.SetFile inpath
If gr.Drawable Then
rc.String = gr(1).Rectangle
rc.Top = rc.Top + 20
rc.Left = rc.Left + 20
rc.Bottom = rc.Bottom - 20
rc.Right = rc.Right - 20
|
|
|
|
|
|
|
|
|
|
The default size of the Canvas is the natural, un-cropped size
of the first image drawn on it. We are going to crop the image so
we have to manually set the Canvas size to take this into account.
We also use the Pos parameter to shift the image up and left to
cater for our border width.
[VBScript]
ca.Height = rc.Height
ca.Width = rc.Width
ca.DrawFile inpath, "Pos=-20,-20 SrcRect=" &
rc.String
|
|
|
|
|
|
|
|
|
|
Finally we save the picture as a JPEG image.
[VBScript]
ca.SaveAs outpath , ""
End If
|
|
|
|
|
|
|
|
|
|
Sample input and output images are shown below.
birds.jpg
croppedbirds.jpg
|
|
|
|