Suppose you allow images to be uploaded on your site but they must be of a certain size or maybe you want to resize the image as a percent of the original size. The hurdle by doing it in javascript or jquery is that you have to wait until it is completely loaded or you will get zeros as its dimension. Secondly using Javascript to get the image will give you the image size of the container it is in. So if you create a place holder then you cannot use width or size on the image or the result will be that image container. In other words something like this…
[code language=”js”]
<img src="www.mywebsite.com/img/1.jpg" width="32px" height="32px"/>
[/code]
Will return 32px even though the image might be 900px x 900px. This approach will only work if you do not put the size inside the image.
One solution to this is to run the code on the server. This will provide the actual dimensions. From there you can actually continue processing it or return a message that it needs to be the right size.
[code language=”vb”]
//Put the uploaded image into an image object
Dim UploadedImage as System.Drawing.Image = System.Drawing.Image.FromStream(UploadedFile.PostedFile.InputStream)
//Capture the width and height of uploaded image
Dim UploadedImageWidth as float = UploadedImage.PhysicalDimension.Width
Dim UploadedImageHeight as float = UploadedImage.PhysicalDimension.Height
If……
end if
[/code]
Looking for quality web hosting? Look no further than Arvixe Web Hosting!