Forum Moderators: open

Message Too Old, No Replies

Image manipulation functions?

         

tesla

11:21 pm on Jul 20, 2002 (gmt 0)

10+ Year Member



With Active server pages is there any image manipulations functions?
For example, would love to have the following functions:

Image_width - returns the width in pixels of a specified image file
Image_height - returns the height
Scale_image - Scales the image of a specified image file to an absolute value or a percentage, and delivers the resulting modified image. The original file is unaltered.
Rotate_image - rotates the image a specified number of degrees.
Flip_image - flips image horizontally or vertically.

I have scanned through the functions documents but I have never seen any image functions.

Any ideas?

Thanks,

tomasz

3:52 am on Jul 21, 2002 (gmt 0)

10+ Year Member



If you are using ASP the you have to use ASPImage or similar package.
Most of the Window hosting company will include this component in hosting package.
With dot net image manipulation is a little bite simpler, Here is some code which takes Uploaded image , check for dimensions, creates, 400*300 or 300*400 pixels picture, rotates image

Imports System.Drawing.Imaging

...
uploadImage = System.Drawing.Image.FromStream(ImageUpload.PostedFile.InputStream)

...

Private Function CreatePicture(ByVal ImageUpload As System.Drawing.Image) As Boolean
dim startingPath ="whatever"
Dim lngWidth As Long
Dim lngHeight As Long

Dim IntX As IntPtr = New IntPtr()

' Obtain Image Object Reference from Uploaded Filestream
Dim uploadImage As System.Drawing.Image
Dim resizedImage As System.Drawing.Image

lngWidth = ImageUpload.Width
lngHeight = ImageUpload.Height
Dim intWidth As Integer
Dim intHeight As Integer

If lngHeight / lngWidth < 1 Then
'horizontal
intWidth = 300
intHeight = CInt(300 * lngHeight / lngWidth)
Else
'vertical
intWidth = CInt(300 * lngWidth / lngHeight)
intHeight = 300
End If

If boolFirst Then
End If
'get thumb
Dim intThWidth As Integer = CInt(66 * lngWidth / lngHeight)

If intThWidth < 120 Then
resizedImage = ImageUpload.GetThumbnailImage(intThWidth, 66, Nothing, IntX)

Else
resizedImage = ImageUpload.GetThumbnailImage(120, CInt(120 * lngHeight / lngWidth), Nothing, IntX)
End If
'now you can rotate it
resizedImage.RotateFlip(RotateFlipType.Rotate90FlipX) 'lets rotate it

resizedImage.Save(startingPath + "\thumbs\Picture.jpg", ImageFormat.Jpeg)

'save picture
Dim thumb As Bitmap = New Bitmap(ImageUpload, New Size(intWidth, intHeight))
thumb.Save(startingPath + "\pictures\thumb.jpg", ImageFormat.Jpeg)

CreatePicture = True
......

You can do prety much the same in ASP with ASPImage

reference
[p2p.wrox.com...]

ecardiff

7:11 am on Jul 21, 2002 (gmt 0)

10+ Year Member



Have a look at this link [4guysfromrolla.com] at 4guysfromrolla.

I've used it and it's excellent - pure ASP (no components) to determine size, height, width and colour depth of images.

It won't of course help with rotating/flipping an image, but you may find it useful.

tesla

7:24 am on Jul 21, 2002 (gmt 0)

10+ Year Member



ecardiff,

I think the problem with this approach is that this information is determined by the client after the fact. That is after the image is pushed to the users browser. I would like to manipulate the image before it is pushed across. In this way I'm not pushing big images only to shrink them down or alter them in some way.

I often have on original source image that I alter in various ways to present to the user. Right now I keep each and every version as a separate file. Of course this method is very reliable and fast, but it takes up a lot of disk space and it takes longer to create image sources.

Thanks,

tesla

4:33 pm on Jul 21, 2002 (gmt 0)

10+ Year Member



I should also mention that the images I'm talking about are often table cell background images. So the image heigth and width parameters don't apply.

I don't think my host is going go for putting a component on the server.

I wonder if a simple Java Applet would be the answer. In searching around I really can't find one that does just the basics as described. Plus I'm concerned about the speed.
If I could find one that simple resized and fliped images around both horizontal or vertical axis, I would be set.