Best way to get image dimensions using ImageResizer

前端 未结 1 1561
走了就别回头了
走了就别回头了 2021-01-23 12:57

I am switching an existing MVC 4 website from home-cooked user file uploads to resizing files with ImageResizer as they are uploaded.

I see in the documentation that I

1条回答
  •  迷失自我
    2021-01-23 13:20

    If you can store the image dimensions during upload (from ImageJob.SourceWidth/Height or LoadImageInfo), that is best, as reading image dimensions from a file involves lots of I/O.

    If not, ImageResizer offers the IDictionary LoadImageInfo(object source, IEnumerable requestedInfo) method to do so after the fact. Just keep in mind, it does involve reading from disk, and you don't want to call this lots of times in a single HTTP request. Put those numbers in the database.

    You can always calculate the final size of an image via ImageBuilder.GetFinalSize(originalSize, instructions). This, on the other hand, is very fast, as it involves no I/O, just math.

    0 讨论(0)
提交回复
热议问题