Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Anthony Candaele 1197 posts 2049 karma points
    Jan 25, 2014 @ 11:22
    Anthony Candaele
    0

    DAMP: create more then one crop

    Hi,

    Is there a way with Damp to create more then one crop for an image. I need a smaller version of an image then the crop i defined for it, to appear in the featured section on the homepage.

    thanks for your help and suggestions,

    Anthony

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 25, 2014 @ 19:10
    Jeroen Breuer
    1

    Hello,

    DAMP doesn't create crops. Those are other packages or the built in cropper. Which crop tool are you using?

    Jeroen

  • Anthony Candaele 1197 posts 2049 karma points
    Jan 30, 2014 @ 15:14
    Anthony Candaele
    0

    Hi Jeroen,

    I'm using the built in image cropper.

    greetings,

    Anthony

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 31, 2014 @ 20:39
    Jeroen Breuer
    0

    If you use the default image cropper why don't you just add a smaller crop version of the image on the datatype?

    Jeroen

  • Anthony Candaele 1197 posts 2049 karma points
    Mar 23, 2014 @ 15:43
    Anthony Candaele
    0

    Hi Jeroen,

    I created two crop versions:

    enter image description here

    But when I try to choose a crop for my document type, DAMP selects them both:

    enter image description here

    In umbraco.config it's looks like both crops are selected:

    <behandelingCrop>
      <crops date="2014-03-23T10:32:26">
        <crop name="behandelingCrop" x="0" y="0" x2="159" y2="267" url="/media/1027/b-active-gamma_behandelingCrop.jpg" />
        <crop name="behandelingCrop" x="0" y="0" x2="300" y2="267" url="/media/1027/b-active-gamma_behandelingCrop.jpg" />
       </crops>
     </behandelingCrop>
    

    What I would like is that an editor can choose between the two crops and DAMP saves the selected crop.

    greetings,

    Anthony

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 23, 2014 @ 16:13
    Jeroen Breuer
    1

    Hello,

    Crop names need to be unique so you can't name both crops behandelingCrop.

    Jeroen

  • Anthony Candaele 1197 posts 2049 karma points
    Mar 23, 2014 @ 16:49
    Anthony Candaele
    0

    Hi Jeroen,

    I see, but then, how do I read out the right crop from the Razor macro file, now my code for reading out the crop looks like this:

    @if (Model.Content.HasValue("behandelingImage"))
    {
        var image = Model.Content.GetPropertyValue<DAMP.PropertyEditorValueConverter.Model>("behandelingImage");
        <img class="polaroid" src="@image.First.TypedCrops["behandelingcrop"]" alt="@image.First.Alt" />
    }
    

    let's say I defined a second crop, behandeling2crop, how can I know which crop - behandelingcrop or behandeling2crop - was selected by the editor?

    thanks for your help,

    Anthony

  • Anthony Candaele 1197 posts 2049 karma points
    Mar 23, 2014 @ 18:33
    Anthony Candaele
    0

    I defined a second crop, for the same image cropper:

    enter image description here

    but when I select a crop with DAMP, both crops are stored in the umbraco.config file:

    <behandelingCrop>
                    <crops date="2014-03-23T17:39:11">
                      <crop name="behandelingCrop" x="0" y="33" x2="300" y2="265" url="/media/1024/b-active-gamma_behandelingCrop.jpg" />
                      <crop name="behandeling2Crop" x="141" y="0" x2="300" y2="266" url="/media/1024/b-active-gamma_behandeling2Crop.jpg" />
                    </crops>
     </behandelingCrop>
    
  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 23, 2014 @ 19:39
    Jeroen Breuer
    1

    Hello,

    DAMP doesn't know which crop is selected. If you define a crop in DAMP that is only to preview the crop. So if you decide to preview behandeling2crop in DAMP that is the image you'll see when you select images with DAMP. That' is the only thing it does. If you want to preview that crop in Razor you need to do it like this:

    @if (Model.Content.HasValue("behandelingImage"))
    {
        var image = Model.Content.GetPropertyValue<DAMP.PropertyEditorValueConverter.Model>("behandelingImage");
        <img class="polaroid" src="@image.First.TypedCrops["behandeling2crop"]" alt="@image.First.Alt" />
    }

    The editor selected behandeling2crop because that is defined as the crop preview in DAMP.

    Jeroen

  • Anthony Candaele 1197 posts 2049 karma points
    Mar 24, 2014 @ 15:21
    Anthony Candaele
    0

    Oh, so there is no way to have 2 different crops of an image, and then let the editor decide which crop to use?

    Thanks for your help,

    Anthony

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Mar 24, 2014 @ 17:56
    Jeroen Breuer
    100

    No not really. You could of course create a dropdown datatype and let the user choose a crop there. Than in your Razor code you use the value of the dropdown in your TypedCrops["behandeling2crop"] code.

    Jeroen

  • Anthony Candaele 1197 posts 2049 karma points
    Mar 30, 2014 @ 15:18
    Anthony Candaele
    0

    Hi Jeroen,

    I tried out your workaround and it works fine. I created a datatype of type dropdown with two property values: landscape and portrait:

    enter image description here

    Then in my Razor code, i use a condition to decide which crop to use:

        var scale = Model.Content.GetPropertyValue("imageScale");
        if (scale.ToString() == "landscape")
        {
        <img class="polaroid" src="@image.First.TypedCrops["behandelingcrop"]" alt="@image.First.Alt" />
        }
        else {
            <img class="polaroid" src="@image.First.TypedCrops["behandeling2crop"]" alt="@image.First.Alt" />
        }
    

    thanks for the tip,

    Anthony

Please Sign in or register to post replies

Write your reply to:

Draft