AntiYes Image Resizer

ImageResizer Documentation

Resize Images

  • By Height
  • By Width
  • Absolute Size


Example


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ResizerTest._Default" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FileUpload runat="server" ID="fupload" />
        <asp:Button runat="server" ID="btnSubmit" Text="Upload" OnClick="btnSubmit_Click" /><br />
        Width:
        <asp:TextBox runat="server" ID="txtWidth" Text="250" />
        <br />
        Quality:
        <asp:TextBox runat="server" ID="txtQuality" Text="75" />
        <br />
        <asp:Image runat="server" ID="imgOriginal" Visible="false" />
        <asp:Image runat="server" ID="imgResized" Visible="false" /><br />
    </div>
    </form>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.IO;
using AntiYes;
using System.Drawing.Imaging;
 
namespace ResizerTest
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
 
        }
 
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (fupload.PostedFile.ContentLength > 0)
            {
                int width = Convert.ToInt32(txtWidth.Text);
                long quality = Convert.ToInt64(txtQuality.Text);
 
                using (ImageResizer ir = new ImageResizer(quality))
                {
                    ir.ResizeByWidth(fupload.PostedFile.InputStream, width);
                    string path = Server.MapPath("~/Upload");
                    string basename = Path.GetFileNameWithoutExtension(fupload.FileName) + "_resized";
                    string filename = ir.SaveAs(path, basename, ImageFormat.Jpeg);
                    imgResized.ImageUrl = "~/Upload/" + filename;
                }
 
                fupload.SaveAs(Server.MapPath(@"~/Upload/" + fupload.FileName));
                imgOriginal.ImageUrl = @"~/Upload/" + fupload.FileName;
                imgOriginal.Visible = true;
                imgResized.Visible = true;
            }
        }
    }
}