public virtual bool OnGetImageSize(string url, bool titledImage, out int width, out int height)
        {
            if (GetImageSize != null)
            {
                var info = new ImageInfo { url = url, titled_image = titledImage };
                if (GetImageSize(info))
                {
                    width = info.width;
                    height = info.height;
                    return true;
                }
            }

            width = 0;
            height = 0;

            if (Utils.IsUrlFullyQualified(url))
                return false;

            // Work out base location
            var str = url.StartsWith("/") ? DocumentRoot : DocumentLocation;
            if (String.IsNullOrEmpty(str))
                return false;

            // Work out file location
            if (str.EndsWith("/") || str.EndsWith("\\"))
            {
                str = str.Substring(0, str.Length - 1);
            }

            if (url.StartsWith("/"))
            {
                url = url.Substring(1);
            }

            str = str + "\\" + url.Replace("/", "\\");

            try
            {
                var img = Image.FromFile(str);
                width = img.Width;
                height = img.Height;

                if (MaxImageWidth != 0 && width > MaxImageWidth)
                {
                    height = (int)(height * (double)MaxImageWidth / width);
                    width = MaxImageWidth;
                }

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
Example #2
0
        // Override to supply the size of an image
        public virtual bool OnGetImageSize(string url, bool TitledImage, out int width, out int height)
        {
            if (GetImageSize != null)
            {
                var info = new ImageInfo() { url = url, titled_image=TitledImage };
                if (GetImageSize(info))
                {
                    width = info.width;
                    height = info.height;
                    return true;
                }
            }

            width = 0;
            height = 0;

            if (Utils.IsUrlFullyQualified(url))
                return false;

            // Work out base location
            string str = url.StartsWith("/") ? DocumentRoot : DocumentLocation;
            if (String.IsNullOrEmpty(str))
                return false;

            // Work out file location
            if (str.EndsWith("/") || str.EndsWith("\\"))
            {
                str=str.Substring(0, str.Length-1);
            }

            if (url.StartsWith("/"))
            {
                url=url.Substring(1);
            }

            str=str + "\\" + url.Replace("/", "\\");

            //

            //Create an image object from the uploaded file
            try
            {
                var img = new BitmapImage(new Uri(str,UriKind.Absolute));
                width=img.PixelWidth;
                height=img.PixelHeight;

                if (MaxImageWidth != 0 && width>MaxImageWidth)
                {
                    height=(int)((double)height * (double)MaxImageWidth / (double)width);
                    width=MaxImageWidth;
                }

                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
Example #3
0
		// Override to supply the size of an image
		public virtual bool OnGetImageSize(string url, bool TitledImage, out int width, out int height)
		{
			if (GetImageSize != null)
			{
				var info = new ImageInfo() { url = url, titled_image=TitledImage };
				if (GetImageSize(info))
				{
					width = info.width;
					height = info.height;
					return true;
				}
			}

			width = 0;
			height = 0;

			if (Utils.IsUrlFullyQualified(url))
				return false;

			// Work out base location
			string str = url.StartsWith("/") ? DocumentRoot : DocumentLocation;
			if (String.IsNullOrEmpty(str))
				return false;

			// Work out file location
			if (str.EndsWith("/") || str.EndsWith("\\"))
			{
				str=str.Substring(0, str.Length-1);
			}

			if (url.StartsWith("/"))
			{
				url=url.Substring(1);
			}

			str=str + "\\" + url.Replace("/", "\\");


			// 
			return true;
//			//Create an image object from the uploaded file
//			try
//			{
//				var img = System.Drawing.Image.FromFile(str);
//				width=img.Width;
//				height=img.Height;
//
//				if (MaxImageWidth != 0 && width>MaxImageWidth)
//				{
//					height=(int)((double)height * (double)MaxImageWidth / (double)width);
//					width=MaxImageWidth;
//				}
//
//				return true;
//			}
//			catch (Exception)
//			{
//				return false;
//			}
		}
		// Override to supply the size of an image
		public virtual bool OnGetImageSize(string url, bool TitledImage, out nint width, out nint height)
		{
			if (GetImageSize != null)
			{
				var info = new ImageInfo() { url = url, titled_image=TitledImage };
				if (GetImageSize(info))
				{
					width = info.width;
					height = info.height;
					return true;
				}
			}

			width = 0;
			height = 0;

			if (Utils.IsUrlFullyQualified(url))
				return false;

			// Work out base location
			string str = url.StartsWith("/") ? DocumentRoot : DocumentLocation;
			//if (String.IsNullOrEmpty(str))
			if (null != str && str != System.String.Empty)
				return false;

			// Work out file location
			if (str.EndsWith("/") || str.EndsWith("\\"))
			{
				str=str.Substring(0, str.Length-1);
			}

			if (url.StartsWith("/"))
			{
				url=url.Substring(1);
			}

			str=str + "\\" + url.Replace("/", "\\");


			// 

			//Create an image object from the uploaded file
			try
			{
				PatchSystemDrawingImageFromFile(ref width, ref height, str);

				return true;
			}
			catch (Exception)
			{
				return false;
			}
		}
Example #5
0
        // Override to supply the size of an image
        public virtual bool OnGetImageSize(string url, bool TitledImage, out int width, out int height)
        {
            if (GetImageSize != null)
            {
                var info = new ImageInfo()
                {
                    url = url, titled_image = TitledImage
                };
                if (GetImageSize(info))
                {
                    width  = info.width;
                    height = info.height;
                    return(true);
                }
            }

            width  = 0;
            height = 0;

            if (Utils.IsUrlFullyQualified(url))
            {
                return(false);
            }

            // Work out base location
            string str = url.StartsWith("/") ? DocumentRoot : DocumentLocation;

            if (String.IsNullOrEmpty(str))
            {
                return(false);
            }

            // Work out file location
            if (str.EndsWith("/") || str.EndsWith("\\"))
            {
                str = str.Substring(0, str.Length - 1);
            }

            if (url.StartsWith("/"))
            {
                url = url.Substring(1);
            }

            str = str + "\\" + url.Replace("/", "\\");


            //
            return(true);
//			//Create an image object from the uploaded file
//			try
//			{
//				var img = System.Drawing.Image.FromFile(str);
//				width=img.Width;
//				height=img.Height;
//
//				if (MaxImageWidth != 0 && width>MaxImageWidth)
//				{
//					height=(int)((double)height * (double)MaxImageWidth / (double)width);
//					width=MaxImageWidth;
//				}
//
//				return true;
//			}
//			catch (Exception)
//			{
//				return false;
//			}
        }