|
|
 |
| Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Professional section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

November 3rd, 2003, 08:13 AM
|
|
Authorized User
|
|
Join Date: Jul 2003
Location: , , .
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
How Can I Crop An Image in ASP
Hiya
I'm using some code that allows me to browse for an image on my hard drive, click upload and this then uploads my image to a specified folder on my website. This image name then gets placed into a field on an insert page which is then entered into a database.
The front end of my site calls this data from the database and displays the corresponding image for a particular record. However, I need to make sure that the image that's uploaded is the correct width.
Is it possible, before my image is uploaded to the specified folder, that this image can be cropped so that it's exactly the right size. I need to be able to specify the width, but the height can vary (as some images may be square, whilst others may be rectangular portrait).
Can this be done with a bit of ASP code?
Thanks in advance.
Lucy Robinson
|

November 3rd, 2003, 11:33 AM
|
 |
Friend of Wrox
Points: 16,368, Level: 55 |
|
|
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,394
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Do you mean that you want to resize to your specified size? I don't imagine you really mean to crop it. I have some code that does this very thing, let me dig it up and I'll post it.
Peter
----------------------------------------
Work smarter, not harder.
|

November 3rd, 2003, 11:52 AM
|
 |
Friend of Wrox
Points: 16,368, Level: 55 |
|
|
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,394
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Using the System.Drawing classes you can do all sorts of image processing. Here's a class file I wrote for an image browser application. I figured the whole thing would be useful for you.
Public Class ImageTools
Private Enum ResizeType
PixelFixed
PixelMax
Percent
End Enum
Private Enum ResizeOp
Thumbnail
Bitmap
End Enum
Public Class Thumbnail
Public Shared Function ToMaxDimensions(ByVal image As System.Drawing.Image, ByVal maxHeight As Integer, ByVal maxWidth As Integer) As System.Drawing.Image
Return DoResize(image, ResizeType.PixelMax, maxHeight, maxWidth, ResizeOp.Thumbnail)
End Function
Public Shared Function ToSize(ByVal image As System.Drawing.Image, ByVal height As Integer, ByVal width As Integer) As System.Drawing.Image
Return DoResize(image, ResizeType.PixelFixed, height, width, ResizeOp.Thumbnail)
End Function
Public Shared Function ToPercent(ByVal image As System.Drawing.Image, ByVal percent As Byte) As System.Drawing.Image
Return DoResize(image, ResizeType.Percent, percent, percent, ResizeOp.Thumbnail)
End Function
End Class
Public Class Resize
Public Shared Function ToMaxDimensions(ByVal image As System.Drawing.Image, ByVal maxHeight As Integer, ByVal maxWidth As Integer) As System.Drawing.Image
Return DoResize(image, ResizeType.PixelMax, maxHeight, maxWidth, ResizeOp.Bitmap)
End Function
Public Shared Function ToSize(ByVal image As System.Drawing.Image, ByVal height As Integer, ByVal width As Integer) As System.Drawing.Image
Return DoResize(image, ResizeType.PixelFixed, height, width, ResizeOp.Bitmap)
End Function
Public Shared Function ToPercent(ByVal image As System.Drawing.Image, ByVal percent As Byte) As System.Drawing.Image
Return DoResize(image, ResizeType.Percent, percent, percent, ResizeOp.Bitmap)
End Function
End Class
Private Shared Function DoResize(ByVal objImage As System.Drawing.Image, ByVal eType As ResizeType, ByVal nTargetHeight As Integer, ByVal nTargetWidth As Integer, ByVal eResizeOp As ResizeOp) As System.Drawing.Image
Dim nCurrentHeight As Integer
Dim nCurrentWidth As Integer
Dim nNewHeight As Integer
Dim nNewWidth As Integer
Dim objAdjustedImage As System.Drawing.Image
nCurrentHeight = objImage.Height
nCurrentWidth = objImage.Width
Select Case eType
Case ResizeType.Percent
nNewHeight = CType(nCurrentHeight * (nTargetHeight / 100), Integer)
nNewWidth = CType(nCurrentWidth * (nTargetWidth / 100), Integer)
Case ResizeType.PixelFixed
nNewHeight = nTargetHeight
nNewWidth = nTargetWidth
Case ResizeType.PixelMax
Select Case True
Case nCurrentHeight = nCurrentWidth
nNewHeight = System.Math.Max(nTargetHeight, nTargetWidth)
nNewWidth = nNewHeight
Case nCurrentHeight > nCurrentWidth
nNewHeight = nTargetHeight
nNewWidth = CType(nCurrentWidth * (nNewHeight / nCurrentHeight), Integer)
Case nCurrentWidth > nCurrentHeight
nNewWidth = nTargetWidth
nNewHeight = CType(nCurrentHeight * (nNewWidth / nCurrentWidth), Integer)
End Select
End Select
If nNewHeight >= nCurrentHeight And nNewWidth >= nCurrentWidth Then
objAdjustedImage = objImage
Else
Select Case eResizeOp
Case ResizeOp.Bitmap
objAdjustedImage = New Bitmap(objImage, nNewWidth, nNewHeight)
Case ResizeOp.Thumbnail
objAdjustedImage = objImage.GetThumbnailImage(nNewWidth, nNewHeight, Nothing, IntPtr.Zero)
End Select
End If
Return objAdjustedImage
End Function
End Class
Peter
----------------------------------------
Work smarter, not harder.
|

November 4th, 2003, 07:15 AM
|
|
Authorized User
|
|
Join Date: Jul 2003
Location: , , .
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Cheers for all your help Peter - and thanks for the code - I think it's gonna be extremely useful :)
Lucy
|

November 6th, 2003, 12:28 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Copenhagen N, , Denmark.
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Peter.
That code looks very useful but is it not ASP.NET and not classic ASP?
While I know only VBScript and JScript for classic ASP, this looks alot like VB. I would like to use your code and I've got .NET, but how do I implement it in a classic ASP site?
Perhaps like this:
<%
Dim objImageTools
Set objImageTools = New ImageTools
...
Regards - Jon
|

November 6th, 2003, 12:38 PM
|
 |
Friend of Wrox
Points: 16,368, Level: 55 |
|
|
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,394
Thanks: 0
Thanked 2 Times in 2 Posts
|
|
Wow.. now I feel like an idiot. I replied to this topic without even noticing it was the ASP forum, not an ASP.Net one!
Because these methods take and return .Net objects, you wouldn't be able to use them directly in class ASP.
HOWEVER!... ;)
With some modifications, one might be able to change the methods to handle simpler arrays that hold the binary data of an image, then you could compile this code in a .Net assembly that was set up to register for COM interop. Then you could use it in classic asp. (this is all just theoretical of course. :D)
Peter
------------------------------------------------------
Work smarter, not harder.
|

November 6th, 2003, 12:48 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Location: Copenhagen N, , Denmark.
Posts: 217
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I think I just stick to serverobjects.com :D
Regards - Jon
|

July 16th, 2008, 06:07 AM
|
|
Registered User
|
|
Join Date: Jul 2008
Location: Brisbane, QLD, Australia.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Cropping images online has come a long way since....
Here's an article on how to crop images using javascript and ASP
http://www.imagecowboy.com/articles/...javascript.asp
live hard, live wide, live long and don't regret
Last edited by googleme : January 30th, 2009 at 03:59 AM.
Reason: domain name change
|

August 28th, 2009, 04:38 PM
|
|
Registered User
|
|
Join Date: Aug 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
i think this component can help you:
http://i-load.radactive.com/
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |