More in this section

Forums / Developing with Sitefinity / Adding an image field to a custom module in 4.2

Adding an image field to a custom module in 4.2

6 posts, 0 answered
  1. Jack Murphy
    Jack Murphy avatar
    8 posts
    Registered:
    25 Aug 2009
    16 Jan 2012
    Link to this post
    What's the best method for adding images to a custom module?

    I've tried specifying the type of the backing field as a string and using the following as the backend editor:

    var bSpotImage = new ImageFieldElement(bSpotSection.Fields)
    {
        ID = "bSpotImageField",
        DataFieldName = "BSpotImage",
        Title = "BSpot Image",
        DisplayMode = displayMode,
        CssClass = "sfFormSeparator sfContentField",
        WrapperTag = HtmlTextWriterTag.Li,
        FieldType = typeof(Telerik.Sitefinity.Web.UI.Fields.ImageField)
    };

    But that code always forces a resize on upload. What am I doing wrong? 
  2. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    18 Sep 2017
    17 Jan 2012
    Link to this post
    Hello,

     If you are using Sitefinity 4.2.1650 there is a bug that is fixed in the hotfix for 4.1.1650. The bug was reducing the size of the image on upload

    var productImageField = new ImageFieldElement(mainSection.Fields)
                {
                    ID = "avatarField",
                    DataFieldName = "ProductImage",
                    DisplayMode = displayMode,
                    UploadMode = ImageFieldUploadMode.Dialog,
                    Title = "ProductImageFieldTitle",
                    WrapperTag = HtmlTextWriterTag.Li,
                    CssClass = "sfUserAvatar",
    //specify your module resources here
                    ResourceClassId = typeof(ProductsResources).Name,
                    DataFieldType = typeof(ContentLink),
                    DefaultSrc = "~/SFRes/images/ProductCatalogSample/Images.NoProductImage.png",// put your default image location example if available, if not remove the line:
    //this specifies the resizing during upload
                    SizeInPx = 100
                };
    If this is not specified "SizeInPx" it will take a default value. SizeInPx is a configuration property of the ImageFieldElement so it is better to set is explicitly to a required value.
    Greetings,
    Stanislav Velikov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Jack Murphy
    Jack Murphy avatar
    8 posts
    Registered:
    25 Aug 2009
    17 Jan 2012
    Link to this post
    I am running 4.2.1650. Can you provide a link to this hotfix? 

    Thanks for your help.
  4. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    18 Sep 2017
    18 Jan 2012
    Link to this post
    Hi,

    Excuse me I was mistaken the problem with images being resized was in Sitefinity 4.3.1873 and was fixed in 4.3.1885(the problem was when uploading an image with size 1mb displaying and downloading it returned an image of 200Kb which reduces quality).

    In this case I suppose the problem in SizeInPx propery for the ImageFieldElement.
    If this doesn`t help can you elaborate a little more about is the resize in image size in (Kb, Mb) or in size (pixels).

    All the best,
    Stanislav Velikov
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  5. Jack Murphy
    Jack Murphy avatar
    8 posts
    Registered:
    25 Aug 2009
    18 Jan 2012
    Link to this post
    Both? It seems to be primarily a change in dimensions. I've outlined what I think are the important bits below. 

    From the Definitions:
    var landingImage = new ImageFieldElement(landingSection.Fields)
    {
        ID = "landingImageUrl",
        DataFieldName = "LandingImageUrl",
        Title = "Landing Image Url",
        DisplayMode = displayMode,
        CssClass = "sfFormSeparator sfContentField",
        WrapperTag = HtmlTextWriterTag.Li,
        FieldType = typeof(Telerik.Sitefinity.Web.UI.Fields.ImageField),
        SizeInPx = 448
    };
    landingSection.Fields.Add(landingImage);

    From the Model:
    [DataMember]
    public string LandingImageUrl { get; set; }

    From the View Model:
    public string LandingImageUrl { get; set; }

    Specifying the SizeInPx property seems to have no effect whatsoever. After uploading test.jpg  the database contains the following url http://localhost/case-studies/test.jpg.tmb and has been reduced in size.



  6. Jack Murphy
    Jack Murphy avatar
    8 posts
    Registered:
    25 Aug 2009
    18 Jan 2012
    Link to this post
    FYI, I've created a support ticket where you can find the source for the entire module.
6 posts, 0 answered