Exemplo n.º 1
0
        /// <summary>
        /// Sets the size of the thumbnail base on the size parameter.
        /// </summary>
        /// <param name="size">The size parameter.</param>
        private void SetSize(string size)
        {
            int sizeVal;
              if (!Int32.TryParse(size.Trim(), System.Globalization.NumberStyles.Integer, null, out sizeVal))
            sizeVal = (int)ThumbnailSizeType.Small;

              try
              {
            this._sizeType = (ThumbnailSizeType)sizeVal;
              }
              catch
              {
            this._sizeType = ThumbnailSizeType.Small;
              }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Main interface for reacting to the Thumbnailer request.
        /// </summary>
        /// <param name="context"></param>
        protected override void HandleRequest(HttpContext context)
        {
            if (string.IsNullOrEmpty(context.Request.QueryString[SIZE_PARAM]))
            this._sizeType = ThumbnailSizeType.Small;
              else
            this.SetSize(context.Request.QueryString[SIZE_PARAM]);

              if ((string.IsNullOrEmpty(context.Request.QueryString[IMG_PARAM])) ||
               (!this.IsValidImage(context.Request.QueryString[IMG_PARAM])))
              {
            this.GetDefaultImage(context);
              }
              else
              {
            string file = context.Request.QueryString[IMG_PARAM].Trim().ToLower().Replace("\\", "/");
            if (file.IndexOf("/") != 0)
              file = "/" + file;

            if (!File.Exists(context.Server.MapPath("~" + file)))
              this.GetDefaultImage(context);
            else
            {
              using (System.Drawing.Image im = System.Drawing.Image.FromFile(context.Server.MapPath("~" + file)))
              using (System.Drawing.Image tn = this.CreateThumbnail(im))
              {
            tn.Save(context.Response.OutputStream, this._formatType);
              }
            }
              }
        }