Retrieve deleted image sizes

Given the URL of the image (rather than the image itself), what is most effective for measuring it? I would like to change the height and width attributes in the image tag ( <img>) if it is more than 200x200. However, if it is smaller than this, then I would like to keep the size as is. (I am using ASP.NET/C#)

+3
source share
4 answers

If you do not want to check the properties of the image by downloading it first, you can do this using javascript:

<img src="image.jpg" onload="if( this.width > 200 ) this.width = 200;">
+1
source

, ( , ), <div> max-height max-width , ?

, , , , .

+4

, JPEG, / .

. , , PNG , โ€‹โ€‹ .

+1

http://www.brettb.com/ASPNETUploadImageSize.asp

Sample code comes from the above site. This is for the uploaded image, but it shows you how to get the informatics from the file stream:

private void ButtonUpload_Click(object sender, System.EventArgs e)  {

    //Determine type and filename of uploaded image
    string UploadedImageType = UploadedPicture.PostedFile.ContentType.ToString().ToLower();
    string UploadedImageFileName = UploadedPicture.PostedFile.FileName;

    //Create an image object from the uploaded file
    System.Drawing.Image UploadedImage = System.Drawing.Image.FromStream(UploadedPicture.PostedFile.InputStream);

    //Determine width and height of uploaded image
    float UploadedImageWidth = UploadedImage.PhysicalDimension.Width;
    float UploadedImageHeight = UploadedImage.PhysicalDimension.Height;

    //Check that image does not exceed maximum dimension settings
    if (UploadedImageWidth > 600 || UploadedImageHeight > 400) {
            Response.Write("This image is too big - please resize it!");
    }

}
0
source

Source: https://habr.com/ru/post/1740512/


All Articles