Ejemplo n.º 1
0
        private System.Drawing.Image DownloadImageFromUrl(string imageUrl)
        {
            System.Drawing.Image image = null;

            try
            {
                System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(imageUrl);
                webRequest.AllowWriteStreamBuffering = true;
                webRequest.Timeout = 30000;

                System.Net.WebResponse webResponse = webRequest.GetResponse();

                System.IO.Stream stream = webResponse.GetResponseStream();

                image = System.Drawing.Image.FromStream(stream);

                webResponse.Close();
            }
            catch (Exception ex)
            {
                return(null);
            }

            return(image);
        }
Ejemplo n.º 2
0
        protected void GenerateQR_OnServerClick(object sender, EventArgs e)
        {
            try
            {
                QRCodeGenerator qr = new QRCodeGenerator();
                fileCode = GenerateFileCode();
                QRCodeGenerator.QRCode data =
                    qr.CreateQrCode(
                        fileCode + ", Amt = " + txtamountApproved.Value + ", Contact = " +
                        txtcontactpersonnumber.Value, QRCodeGenerator.ECCLevel.Q);

                System.Web.UI.WebControls.Image codeImage = new System.Web.UI.WebControls.Image();
                codeImage.Height = 162;
                codeImage.Width  = 126;
                using (Bitmap map = data.GetGraphic(20))
                {
                    using (MemoryStream stream = new MemoryStream())
                    {
                        map.Save(stream, ImageFormat.Png);
                        byte[] bImg = stream.ToArray();
                        codeImage.ImageUrl = "data:image/png;base64," + Convert.ToBase64String(bImg);

                        System.Drawing.Image i = System.Drawing.Image.FromStream(stream);
                        i.Save(Server.MapPath("~/img/" + fileCode + ".png"), ImageFormat.Png);
                    }
                }

                qrCodeData.Controls.Add(codeImage);
                btnSubmit.Disabled = false;
            }
            catch (Exception exception)
            {
            }
        }
Ejemplo n.º 3
0
        private System.Drawing.Image resizeImage(System.Drawing.Image imgToResize, Size size)
        {
            int sourceWidth  = imgToResize.Width;
            int sourceHeight = imgToResize.Height;

            float nPercent  = 0;
            float nPercentW = 0;
            float nPercentH = 0;

            nPercentW = ((float)size.Width / (float)sourceWidth);
            nPercentH = ((float)size.Height / (float)sourceHeight);

            if (nPercentH < nPercentW)
            {
                nPercent = nPercentH;
            }
            else
            {
                nPercent = nPercentW;
            }

            int destWidth  = (int)(sourceWidth * nPercent);
            int destHeight = (int)(sourceHeight * nPercent);

            Bitmap   b = new Bitmap(destWidth, destHeight);
            Graphics g = Graphics.FromImage((System.Drawing.Image)b);

            g.InterpolationMode = InterpolationMode.HighQualityBicubic;

            g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
            g.Dispose();

            return((System.Drawing.Image)b);
        }
Ejemplo n.º 4
0
        protected void btnCrop_Click(object sender, EventArgs e)
        {
            int X1 = Convert.ToInt32(Request.Form["x1"]);
            int Y1 = Convert.ToInt32(Request["y1"]);
            int X2 = Convert.ToInt32(Request.Form["x2"]);
            int Y2 = Convert.ToInt32(Request.Form["y2"]);
            int X  = System.Math.Min(X1, X2);
            int Y  = System.Math.Min(Y1, Y2);
            int w  = Convert.ToInt32(Request.Form["w"]);
            int h  = Convert.ToInt32(Request.Form["h"]);

            // That can be any image type (jpg,jpeg,png,gif) from any where in the local server
            string originalFile = Server.MapPath("~/images/02.jpg");


            using (System.Drawing.Image img = System.Drawing.Image.FromFile(originalFile))
            {
                using (System.Drawing.Bitmap _bitmap = new System.Drawing.Bitmap(w, h))
                {
                    _bitmap.SetResolution(img.HorizontalResolution, img.VerticalResolution);
                    using (Graphics _graphic = Graphics.FromImage(_bitmap))
                    {
                        _graphic.InterpolationMode  = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                        _graphic.SmoothingMode      = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                        _graphic.PixelOffsetMode    = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                        _graphic.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                        _graphic.DrawImage(img, 0, 0, w, h);
                        _graphic.DrawImage(img, new Rectangle(0, 0, w, h), X, Y, w, h, GraphicsUnit.Pixel);

                        string extension       = Path.GetExtension(originalFile);
                        string croppedFileName = Guid.NewGuid().ToString();
                        string path            = Server.MapPath("~/cropped/");


                        // If the image is a gif file, change it into png
                        if (extension.EndsWith("gif", StringComparison.OrdinalIgnoreCase))
                        {
                            extension = ".png";
                        }

                        string newFullPathName = string.Concat(path, croppedFileName, extension);

                        using (EncoderParameters encoderParameters = new EncoderParameters(1))
                        {
                            encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 100L);
                            _bitmap.Save(newFullPathName, GetImageCodec(extension), encoderParameters);
                        }

                        lblCroppedImage.Text = string.Format("<img src='cropped/{0}' alt='Cropped image'>", croppedFileName + extension);
                    }
                }
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Returns a Url to the map
 /// </summary>
 private string GenerateMap()
 {
     if (_UseCache)
     {
         System.Drawing.Image img = Map.GetMap();
         string imgID             = Caching.InsertIntoCache(1, img);
         return("getmap.aspx?ID=" + HttpUtility.UrlEncode(imgID));
     }
     else
     {
         return(_ResponseFormat.Replace("[WIDTH]", map.Size.Width.ToString()).
                Replace("[HEIGHT]", map.Size.Height.ToString()).
                Replace("[ZOOM]", map.Zoom.ToString(numberFormat_EnUS)).
                Replace("[X]", map.Center.X.ToString(numberFormat_EnUS)).
                Replace("[Y]", map.Center.Y.ToString(numberFormat_EnUS)));
     }
 }
Ejemplo n.º 6
0
        protected void btnFourNext_OnClick(object sender, EventArgs e)
        {
            if (Session["NewTemplate"] == null)
            {
                for (int i = 0; i < dtlTemplate.Items.Count; i++)
                {
                    var chkTemplateChoose = (CheckBox)dtlTemplate.Items[i].FindControl("chkTemplate");
                    var lImageCompleted   = new List <ImagesInfo>();
                    if (chkTemplateChoose.Checked)
                    {
                        var aTemplateId = ((HiddenField)chkTemplateChoose.Parent.FindControl("hdIdTemplate")).Value;
                        if (!String.IsNullOrEmpty(aTemplateId) || aTemplateId != "0")
                        {
                            ITemplateFacade aTemplateFacade   = new TemplateFacade();
                            var             aTemplateInfo     = aTemplateFacade.GetTemplateInfoById(int.Parse(aTemplateId));
                            var             aListDraggedImage = targetImage.Value.Split('|');
                            string          html         = aTemplateInfo.TemplateContent;
                            string          tmphtml      = "";
                            var             aImagesInfos = (List <ImagesInfo>)Session["ImageLink"];
                            for (int j = 0; j < aListDraggedImage.Length; j++)
                            {
                                var aImageInfo = aImagesInfos.Where(x => x.ImagesLink.Trim() == aListDraggedImage[j].Trim()).FirstOrDefault();
                                if (aImageInfo != null)
                                {
                                    tmphtml += "<div class='sortable-item' style='width:100%'>";

                                    if (!File.Exists(Server.MapPath("~/Upload/") + "/" + aImageInfo.ImagesLink))
                                    {
                                        System.Drawing.Image img = DownloadImageFromUrl(aImageInfo.ImagesLink);
                                        string extension         = Path.GetExtension(aImageInfo.ImagesLink);
                                        string croppedFileName   = Guid.NewGuid().ToString();
                                        string path = Server.MapPath("~/Upload/");


                                        // If the image is a gif file, change it into png
                                        if (extension.EndsWith("gif", StringComparison.OrdinalIgnoreCase))
                                        {
                                            extension = ".png";
                                        }

                                        string newFullPathName = string.Concat(path, croppedFileName, extension);

                                        using (EncoderParameters encoderParameters = new EncoderParameters(1))
                                        {
                                            encoderParameters.Param[0] =
                                                new EncoderParameter(System.Drawing.Imaging.Encoder.Quality,
                                                                     value: 100L);
                                            img.Save(newFullPathName, GetImageCodec(extension), encoderParameters);
                                        }
                                        aImageInfo.ImagesLink =
                                            string.Concat("/Upload/", croppedFileName, extension);
                                        tmphtml += "<img src='" + aImageInfo.ImagesLink + "' />";

                                        lImageCompleted.Add(aImageInfo);
                                    }
                                    else
                                    {
                                        tmphtml += "<img src='" + aImageInfo.ImagesLink + "' />";
                                        lImageCompleted.Add(aImageInfo);
                                    }

                                    if (!String.IsNullOrEmpty(aImageInfo.Title))
                                    {
                                        tmphtml += "<br/><span style='color:red'>" + aImageInfo.Title + "</span>";
                                    }
                                    tmphtml += "</div>";
                                }
                            }
                            html = html.Replace("<div id='myTemplate'></div>", tmphtml);
                            Session["NewTemplate"]   = html;
                            Session["AllImageUsing"] = lImageCompleted;
                        }
                    }
                }
            }

            fieldStep1.Style.Add("display", "none");
            fieldStep2.Style.Add("display", "none");
            fieldStep3.Style.Add("display", "none");
            fieldStep4.Style.Add("display", "none");
            fieldStep5.Style.Add("display", "block");
        }
Ejemplo n.º 7
0
        protected void btnCrop_OnClick(object sender, EventArgs e)
        {
            int X1 = Convert.ToInt32(Request.Form["x1"]);
            int Y1 = Convert.ToInt32(Request["y1"]);
            int X2 = Convert.ToInt32(Request.Form["x2"]);
            int Y2 = Convert.ToInt32(Request.Form["y2"]);
            int X  = System.Math.Min(X1, X2);
            int Y  = System.Math.Min(Y1, Y2);
            int w  = Convert.ToInt32(Request.Form["w"]);
            int h  = Convert.ToInt32(Request.Form["h"]);

            // That can be any image type (jpg,jpeg,png,gif) from any where in the local server
            bool   flag         = true;
            string originalFile = "";
            string oldFile      = "";

            try
            {
                originalFile = Server.MapPath(originalImage.Src);
                oldFile      = Server.MapPath(originalImage.Src);
            }
            catch (Exception ex)
            {
                flag         = false;
                originalFile = originalImage.Src;
            }
            var aImageInfos  = (List <ImagesInfo>)Session["ImageLink"];
            var aImageInfos1 = (List <ImagesInfo>)Session["ImageCroped"];

            var aImageInfo  = aImageInfos.Where(x => x.ImagesLink.Trim() == originalFile).FirstOrDefault();
            var aImageInfo1 = aImageInfos1.Where(x => x.ImagesLink.Trim() == originalFile).FirstOrDefault();

            aImageInfo.Title  = txtTitle.Value;
            aImageInfo1.Title = txtTitle.Value;
            System.Drawing.Image img = null;
            if (flag)
            {
                img = System.Drawing.Image.FromFile(originalFile);
            }
            else
            {
                img = DownloadImageFromUrl(originalFile);
            }
            using (Bitmap _bitmap = new Bitmap(w, h))
            {
                _bitmap.SetResolution(img.HorizontalResolution, img.VerticalResolution);
                using (Graphics _graphic = Graphics.FromImage(_bitmap))
                {
                    _graphic.InterpolationMode  = InterpolationMode.HighQualityBicubic;
                    _graphic.SmoothingMode      = SmoothingMode.HighQuality;
                    _graphic.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                    _graphic.CompositingQuality = CompositingQuality.HighQuality;
                    _graphic.DrawImage(img, 0, 0, w, h);
                    _graphic.DrawImage(img, new Rectangle(0, 0, w, h), X, Y, w, h, GraphicsUnit.Pixel);


                    if (txtAdditionalText.Value.Trim() != "")
                    {
                        // For Transparent Watermark Text
                        int opacity = 255; // range from 0 to 255

                        //SolidBrush brush = new SolidBrush(Color.Red);
                        SolidBrush brush = new SolidBrush(Color.FromArgb(opacity, Color.White));
                        Font       font  = new Font("Arial", 16);
                        _graphic.DrawString(txtAdditionalText.Value, font, brush, new PointF(0, 10));
                    }

                    if (fileUpload.HasFile)
                    {
                        System.Drawing.Image logoImage = System.Drawing.Image.FromStream(fileUpload.PostedFile.InputStream);
                        logoImage = resizeImage(logoImage, new Size(50, 20));
                        _graphic.DrawImage(logoImage,
                                           new Point(w - logoImage.Width - 10, h - logoImage.Height - 10));
                    }


                    string extension       = Path.GetExtension(originalFile);
                    string croppedFileName = Guid.NewGuid().ToString();
                    string path            = Server.MapPath("~/Upload/");


                    // If the image is a gif file, change it into png
                    if (extension.EndsWith("gif", StringComparison.OrdinalIgnoreCase))
                    {
                        extension = ".png";
                    }

                    string newFullPathName = string.Concat(path, croppedFileName, extension);

                    using (EncoderParameters encoderParameters = new EncoderParameters(1))
                    {
                        encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality,
                                                                          value: 100L);
                        _bitmap.Save(newFullPathName, GetImageCodec(extension), encoderParameters);
                    }
                    string filename = string.Concat("/Upload/", croppedFileName + extension);

                    StringBuilder sb = new StringBuilder();
                    sb.Append(" <div class='ns-box ns-other ns-effect-thumbslider ns-type-notice ns-hide'>");
                    sb.Append("<div class='ns-box-inner'>");
                    sb.Append("<div class='ns-thumb'>");
                    sb.Append("<img src='" + filename + "'></div>");
                    sb.Append("<div class='ns-content'><p>" + txtAdditionalText.Value + "</p> </div> </div>");
                    sb.Append("<span class='ns-close'></span>");
                    sb.Append("</div>");
                    lblCroppedImage.Text  += sb.ToString();
                    aImageInfo.ImagesLink  = filename;
                    aImageInfo1.ImagesLink = filename;
                    originalImage.Src      = filename;
                    if (File.Exists(oldFile))
                    {
                        File.Delete(oldFile);
                    }
                }
            }
        }
Ejemplo n.º 8
0
 public static System.Drawing.Image resizeImage(System.Drawing.Image imgToResize, Size size)
 {
     return(new Bitmap(imgToResize, size));
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Calculates the width and height and sets these as data-attributes on the containing div (as well as on the image)
        /// if a width or height value has been supplied then these are used in preference to the image dimensions
        /// if a width or height value has been supplied, and one of these = 0, then it needs to be calculated from the image dimensions (so as to keep the aspect ratio)
        /// </summary>
        private void SetImageAndSize()
        {
            int  width     = 0; // default unknown values
            int  height    = 0;
            Size imageSize = new Size(0, 0);

            if (!string.IsNullOrWhiteSpace(this.options.ImagePropertyAlias))
            {
                string imageUrl = null;

                // used large try/catch block to simply checking for nulls on content / media & members
                try
                {
                    // looking for the specified property
                    switch (uQuery.GetUmbracoObjectType(this.CurrentContentId))
                    {
                    case uQuery.UmbracoObjectType.Document:
                        imageUrl = uQuery.GetDocument(this.CurrentContentId)
                                   .GetAncestorOrSelfDocuments()
                                   .First(x => x.HasProperty(this.options.ImagePropertyAlias))
                                   .GetProperty <string>(this.options.ImagePropertyAlias);
                        break;

                    case uQuery.UmbracoObjectType.Media:
                        imageUrl = uQuery.GetMedia(this.CurrentContentId)
                                   .GetAncestorOrSelfMedia()
                                   .First(x => x.HasProperty(this.options.ImagePropertyAlias))
                                   .GetProperty <string>(this.options.ImagePropertyAlias);
                        break;

                    case uQuery.UmbracoObjectType.Member:
                        imageUrl = uQuery.GetMember(this.CurrentContentId).GetProperty <string>(this.options.ImagePropertyAlias);

                        break;
                    }
                }
                catch
                {
                    // node, media or member with specified property couldn't be found
                    // TODO: if debug mode on, then throw exception, else be silent
                }

                if (!string.IsNullOrWhiteSpace(imageUrl))
                {
                    // attempt to get image from the url
                    string imagePath = HttpContext.Current.Server.MapPath(imageUrl);
                    if (File.Exists(imagePath))
                    {
                        using (System.Drawing.Image image = System.Drawing.Image.FromFile(imagePath))
                        {
                            this.mainImage.ImageUrl = imageUrl;

                            imageSize = image.Size;
                        }
                    }
                }
            }

            if (this.options.Width == 0 && this.options.Height == 0)
            {
                // neither value set, so use image dimensions
                width  = imageSize.Width;
                height = imageSize.Height;
            }
            else if (this.options.Width > 0 && this.options.Height == 0)
            {
                // width set, so calculate height
                width = this.options.Width;

                if (imageSize.Height > 0)
                {
                    height = (int)(imageSize.Height / ((decimal)imageSize.Width / (decimal)this.options.Width));
                }
            }
            else if (this.options.Width == 0 && this.options.Height > 0)
            {
                // height set, so calculate width
                if (imageSize.Width > 0)
                {
                    width = (int)(imageSize.Width / ((decimal)imageSize.Height / (decimal)this.options.Height));
                }

                height = this.options.Height;
            }
            else if (this.options.Width > 0 && this.options.Height > 0)
            {
                // width and height set, so stretch image to fit
                width  = this.options.Width;
                height = this.options.Height;
            }

            //this.mainImage.Width = width;
            this.mainImage.Attributes["width"] = width.ToString();

            //this.mainImage.Height = height;
            this.mainImage.Attributes["height"] = height.ToString();
        }
Ejemplo n.º 10
0
        protected void btnPreview_OnClick(object sender, EventArgs e)
        {
            var lImageCompleted = new List<ImagesInfo>();
            string aTemplateId = "0";
            bool flag = false;
            for (int i = 0; i < dtlTemplate.Items.Count; i++)
            {
                var chkTemplateChoose = (RadioButton)dtlTemplate.Items[i].FindControl("rboChooser");
               
                if (chkTemplateChoose.Checked)
                {
                    aTemplateId = ((HiddenField)chkTemplateChoose.Parent.FindControl("hdIdTemplate")).Value;
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                aTemplateId = "1";
            }
            if (!String.IsNullOrEmpty(aTemplateId) || aTemplateId != "0")
            {
                ITemplateFacade aTemplateFacade = new TemplateFacade();
                var aTemplateInfo = aTemplateFacade.GetTemplateInfoById(int.Parse(aTemplateId));
                var aListDraggedImage = targetImage.Value.Split('|');
                var aListDraggedTitle = targetTitle.Value.Split('|');
                string path1 = Server.MapPath("~/" + aTemplateInfo.TemplateContent);
                string html = File.ReadAllText(path1);
                string tmphtml = "";
                var aImagesInfos = (List<ImagesInfo>)Session["ImageLink"];
                for (int j = 0; j < aListDraggedImage.Length; j++)
                {
                    var aImageInfo = aImagesInfos.Where(x => x.ImagesLink.Trim() == aListDraggedImage[j].Trim()).FirstOrDefault();
                    
                    if (aImageInfo != null)
                    {
                        try
                        {
                            if (!String.IsNullOrEmpty(aListDraggedTitle[j]))
                            {
                                aImageInfo.Title = aListDraggedTitle[j];
                            }
                        }
                        catch (Exception)
                        {
                        }
                        
                        tmphtml += "<div class='sortable-item' style='width:100%'>";

                        if (!File.Exists(Server.MapPath("~/Upload/") + "/" + aImageInfo.ImagesLink))
                        {
                            System.Drawing.Image img = DownloadImageFromUrl(aImageInfo.ImagesLink);
                            string extension = Path.GetExtension(aImageInfo.ImagesLink);
                            string croppedFileName = Guid.NewGuid().ToString();
                            string path = Server.MapPath("~/Upload/");


                            // If the image is a gif file, change it into png
                            if (extension.EndsWith("gif", StringComparison.OrdinalIgnoreCase))
                            {
                                extension = ".png";
                            }

                            string newFullPathName = string.Concat(path, croppedFileName, extension);

                            using (EncoderParameters encoderParameters = new EncoderParameters(1))
                            {
                                encoderParameters.Param[0] =
                                    new EncoderParameter(System.Drawing.Imaging.Encoder.Quality,
                                        value: 100L);
                                img.Save(newFullPathName, GetImageCodec(extension), encoderParameters);
                            }
                            aImageInfo.ImagesLink =
                                string.Concat("/Upload/", croppedFileName, extension);
                            tmphtml += "<img src='" + aImageInfo.ImagesLink + "' />";

                            lImageCompleted.Add(aImageInfo);
                        }
                        else
                        {
                            tmphtml += "<img src='" + aImageInfo.ImagesLink + "' />";
                            lImageCompleted.Add(aImageInfo);
                        }

                        if (!String.IsNullOrEmpty(aImageInfo.Title))
                        {
                            tmphtml += "<br/><div style='text-align:center;'><span style='font-weight:bold;'>" + aImageInfo.Title + "</span></div>";
                        }
                        tmphtml += "</div>";
                    }
                }
                html = html.Replace("<div id='myTemplate'></div>", tmphtml);
                Session["NewTemplate"] = html;
                Session["AllImageUsing"] = lImageCompleted;
               
                if (Session["NewTemplate"] != null)
                {
                    var aStringBuilder = new StringBuilder();
                    aStringBuilder.Append("<script type='text/javascript'>");
                    aStringBuilder.Append("window.open('View.aspx','_blank');");
                    aStringBuilder.Append("</script>");
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(),
                                   "Modal", aStringBuilder.ToString(), false);
                }
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Calculates the width and height and sets these as attributes on the image, and builds a collection of ghost points
        /// if a width or height value has been supplied then these are used in preference to the image dimensions
        /// if a width or height value has been supplied, and one of these = 0, then it needs to be calculated from the image dimensions (so as to keep the aspect ratio)
        /// </summary>
        private void ConfigureControls()
        {
            int  width     = 0; // default unknown values
            int  height    = 0;
            Size imageSize = new Size(0, 0);

            if (!string.IsNullOrWhiteSpace(this.options.ImagePropertyAlias))
            {
                string imageUrl = null;
                int    currentDataTypeDefinitionId = ((XmlData)this.data).DataTypeDefinitionId;
                int    currentPropertyId           = ((XmlData)this.data).PropertyId;

                // determine whether to use the Document / Media or Member api
                switch (uQuery.GetUmbracoObjectType(this.CurrentContentId))
                {
                case uQuery.UmbracoObjectType.Document:

                    Document imageDocument = uQuery.GetDocument(this.CurrentContentId)
                                             .GetAncestorOrSelfDocuments()
                                             .FirstOrDefault(x => x.HasProperty(this.options.ImagePropertyAlias));

                    if (imageDocument != null)
                    {
                        imageUrl = imageDocument.GetProperty <string>(this.options.ImagePropertyAlias);

                        if (this.options.ShowNeighbours)
                        {
                            // get a collection of all documents that could potentially have this imagepoint datatype instance, sharing the same image
                            List <Document> documents = new List <Document>();

                            // add the document containing the shared main image
                            documents.Add(imageDocument);

                            // drill down and get all documents, but stop descending a path if an imagePropertyAlias is found - any descendants of that would use a different image
                            documents.AddRange(imageDocument.GetDescendantDocuments(x => !x.HasProperty(this.options.ImagePropertyAlias)));

                            // for all documents that use this instance of this imagepoint datatype
                            foreach (Document document in documents.Where(x => x.GenericProperties.Select(y => y.PropertyType.DataTypeDefinition.Id).Contains(currentDataTypeDefinitionId)))
                            {
                                // the document may have multiple properties each using this imagepoint datatype instance
                                this.CreateGhostImages(document.GenericProperties.Where(x => x.PropertyType.DataTypeDefinition.Id == currentDataTypeDefinitionId && x.Id != currentPropertyId));
                            }
                        }
                    }

                    break;

                case uQuery.UmbracoObjectType.Media:

                    Media imageMedia = uQuery.GetMedia(this.CurrentContentId)
                                       .GetAncestorOrSelfMedia()
                                       .FirstOrDefault(x => x.HasProperty(this.options.ImagePropertyAlias));
                    if (imageMedia != null)
                    {
                        imageUrl = imageMedia.GetProperty <string>(this.options.ImagePropertyAlias);

                        if (this.options.ShowNeighbours)
                        {
                            List <Media> media = new List <Media>();

                            // add the media item containing the shared main image
                            media.Add(imageMedia);

                            // unfortunately no uQuery extension method, so using a private local
                            media.AddRange(this.GetDescendantMedia(imageMedia, x => !x.HasProperty(this.options.ImagePropertyAlias)));

                            foreach (Media mediaItem in media.Where(x => x.GenericProperties.Select(y => y.PropertyType.DataTypeDefinition.Id).Contains(currentDataTypeDefinitionId)))
                            {
                                this.CreateGhostImages(mediaItem.GenericProperties.Where(x => x.PropertyType.DataTypeDefinition.Id == currentDataTypeDefinitionId && x.Id != currentPropertyId));
                            }
                        }
                    }

                    break;

                case uQuery.UmbracoObjectType.Member:

                    imageUrl = uQuery.GetMember(this.CurrentContentId).GetProperty <string>(this.options.ImagePropertyAlias);

                    // show neighbours not relevant

                    break;
                }

                if (!string.IsNullOrWhiteSpace(imageUrl))
                {
                    // attempt to get image from the url
                    string imagePath = HttpContext.Current.Server.MapPath(imageUrl);
                    if (File.Exists(imagePath))
                    {
                        using (System.Drawing.Image image = System.Drawing.Image.FromFile(imagePath))
                        {
                            this.mainImage.ImageUrl = imageUrl;

                            imageSize = image.Size;
                        }
                    }
                }
            }

            if (this.options.Width == 0 && this.options.Height == 0)
            {
                // neither value set, so use image dimensions
                width  = imageSize.Width;
                height = imageSize.Height;
            }
            else if (this.options.Width > 0 && this.options.Height == 0)
            {
                // width set, so calculate height
                width = this.options.Width;

                if (imageSize.Height > 0)
                {
                    height = (int)(imageSize.Height / ((decimal)imageSize.Width / (decimal)this.options.Width));
                }
            }
            else if (this.options.Width == 0 && this.options.Height > 0)
            {
                // height set, so calculate width
                if (imageSize.Width > 0)
                {
                    width = (int)(imageSize.Width / ((decimal)imageSize.Height / (decimal)this.options.Height));
                }

                height = this.options.Height;
            }
            else if (this.options.Width > 0 && this.options.Height > 0)
            {
                // width and height set, so stretch image to fit
                width  = this.options.Width;
                height = this.options.Height;
            }

            //this.mainImage.Width = width;
            this.mainImage.Attributes["width"] = width.ToString();

            //this.mainImage.Height = height;
            this.mainImage.Attributes["height"] = height.ToString();
        }