November Happy Hour will be moved to Thursday December 5th.

How do I limit the image size in editmode

Vote:
 

Hi,

I am using ImageVault with EPiServer for the first time. How do I set a default size for a image for the editor?

I have a mediareference on my page model like so:

[ResizeEffect(Width=760, Height=428, ResizeMode = ResizeMode.ScaleToFit)]

[BackingType(typeof(PropertyMediaList))]
public virtual MediaReferenceList HeaderImages { get; set; }


However, the editor can still chose whichever width and height he wants in edit mode. I would like to limit that. How is that possible?

Thanks

Thomas

#114753
Dec 19, 2014 13:41
Vote:
 

Hi Thomas!

This can be done by using property settings in admin. See this link for more information http://imagevault.se/en/documentation/api-documentation/?page=episerverplugin/propertymedia.html.

If you want to set the values of the property settings by code Linus has written a great post about that as well, http://world.episerver.com/blogs/Linus-Ekstrom/Dates/2014/10/typed-property-settings/

/Johan

#114785
Edited, Dec 22, 2014 10:53
tmi
Vote:
 

Hi Johan,

I tried to set the properties with code, according to the second link you sent:

[Display(
            Name = "Test product image",
            Description = "Test product image",
            GroupName = SystemTabNames.Content,
            Order = 1)]
        [BackingType(typeof(PropertyMedia))]
        [EPiServer.DataAnnotations.PropertySettings(typeof(TestImageSettings))]
        public virtual MediaReference TestProductImage20150111 { get; set; }

        [ServiceConfiguration(ServiceType = typeof(PropertySettings))]
        public class TestImageSettings : PropertySettings<PropertyMediaSettings>
        {
            public TestImageSettings()
            {
                DisplayName = "Fixed ratio";
            }
            public override PropertyMediaSettings GetPropertySettings()
            {
                return new PropertyMediaSettings
                {
                    Height = 200,
                    Width = 200,
                    ResizeMode = ResizeMode.ScaleToFit
                };
            }

            public override Guid ID
            {
                get { return new Guid("{9A53D3D4-921E-4E45-8C79-6B877A1C59C5}"); }
            }
        }

And it does show as default in the CMS admin panel:

Property settings

However, the CMS image resize-functionality does not respect proportions given in default settings.

It only respects the propertions, if they are given as custom settings.

Do you have an example, where this is working?

Our problem is that for commerce content, it is apparently not possible to manually define custom settings.

Best regards

Theis Iversen

#115149
Edited, Jan 11, 2015 18:05
Vote:
 

Hello Theis.

If I understand your problem correctly, you might want to use the ResizeMode.ScaleToFill instead of ScaleToFit.

That will bring your image to be rendered with the given width and height, and it will be automatically cropped if its proportions doesn't conform to the displayarea.

Please let me know if I misunderstood your problem.

Best regards

/Richard

#115407
Jan 14, 2015 15:28
tmi
Vote:
 

Hi Richard,

Thanks for your reply.

I think you misunderstood the problem, so I'll try to make it more clear :)

When I go to the property settings in CMS -> Admin -> Content Type -> MyPageType -> MyImageVaultProperty -> Custom Settings tab, I see the following:

However, when I go to an instance of this page in CMS -> Edit -> MyPageTypeInstance, and edit the MyImageVaultProperty, I get the following window:

As you see, the crop-window does not enforce the 200x200 property settings. It allows the user to decide arbitrary dimensions.

So our question is basically, why does the crop-window not respect the property settings?

Best regards

#115451
Jan 15, 2015 11:08
Vote:
 

Hi Theis.

When implementing custom PropertySettings, for ImageVault.EPiServer.PropertyMediaSettings, the settings will automatically show up as a Global setting (from code).
The problem is that the setting is not marked as a Default setting, so you will have to select it manually from admin mode, for properties of your choice.

If your goal is to achieve a globally, default setting for PropertyMedia properties, you will have to mark your PropertySettings as a Default setting by inserting one line of code, like this:

        [ServiceConfiguration(ServiceType = typeof(PropertySettings))]
        public class TestImageSettings : PropertySettings<PropertyMediaSettings> {
            public TestImageSettings() {
                DisplayName = "Fixed ratio";
                //////////////////////////////////////////////////////////
                // Add the following line to mark the setting as Default:
                IsDefault = true;
            }
            public override PropertyMediaSettings GetPropertySettings() {
                return new PropertyMediaSettings {
                    Height = 200,
                    Width = 200,
                    ResizeMode = ResizeMode.ScaleToFit
                };
            }

            public override Guid ID {
                get { return new Guid("{9A53D3D4-921E-4E45-8C79-6B877A1C59C5}"); }
            }
        }

Of course, it means these settings will apply to all instances of PropertyMedia, so it wont be an instance-specific setting.
According to EPiServer, it is currently not possible to programatically bind a setting to a specific property instance, but in the future it will be.
So, for now you will have to find other means to reach your goal.

You could have a look at the following blogspot (in Swedish) that present one way of dealing with this problem:

https://www.meridium.se/sv/blogg/forenkla-hanteringen-av-egenskapsinstallningar-i-episerver/

Hope it helps!

Best regards

/Richard



                        
#115856
Edited, Jan 20, 2015 13:41
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.