Copied to clipboard

Flag this post as spam?

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


  • andrew shearer 506 posts 653 karma points
    Aug 31, 2011 @ 01:52
    andrew shearer
    0

    Media Image Crop with razor

    I've seen a few threads around about this, but nothing looks ideal.

    I have a content node with an image property. All i want to do is get a crop of that image with a specified name. What is the best way of doing this?

    uQuery extension? DynamicMedia? my own helper function?

     

  • Toni Becker 146 posts 425 karma points
    Aug 31, 2011 @ 11:04
    Toni Becker
    3

    Okay best way is to use the new .Find.

    1st go to http://nightly.umbraco.org/umbraco%204.7/4.7%20RC/ download the latest 4.7.1 and copy the umbraco.MacroEngines.dll to your existing install for testing.

    2nd you can now acces with the following code.

    Explanation you have a root node and under that children with a property myMediaItem or what you call it.

    foreach(var n in Model.Children)
    {
    var crop = @n.yourProperty.Find("@name","The name of the crop in the image Cropper data type").url
    <img src="@crop" alt="">
    }

    that's how i would use it. Tried a different other ways and that's the cleanest so far.

    Or you could use the Digibiz Advanced Media Picker, there's a Helper Method with GetImageCropperUrl and so on. You could use the forum search our the project page from DAMP. 

  • Arjan H. 221 posts 457 karma points c-trib
    Sep 28, 2012 @ 15:55
    Arjan H.
    0

    I've also been struggling with different methods to fetch crop data. Checking the crop's BaseElement works best for me:

    @{
     
    var image = Model.MediaById(<mediaid>);
     
    var crops = image.mediaCropper;// mediaCropper is the Image Cropper property I added to the Image media type

     
    // check if specific crop exists
     
    if(crops.Find("@name","<cropname>").BaseElement!=null){
       
    // crop exists
       
    <img src="@crops.Find("@name","<cropname>").url" alt="@image.Name"/>
     
    }
     
    else{
       
    // crop doesn't exist, use alternative method (e.g. ImageGen)
     
    }
    }
  • Anthony Candaele 1197 posts 2049 karma points
    Sep 28, 2012 @ 16:44
    Anthony Candaele
    0

    I'm using the Digibiz Advanced Media Picker

    The way I check for a crop is like this:

    @if (Model.HasValue("conferenceImage") && Model.conferenceImage.Count() >0)

    {

        var imageCrop = DAMP_Helper.GetImageCropperUrl(Model.conferenceImage, "conferenceCrop");

        <img src="@imageCrop" alt="@Model.Name"/>

    }

    Hope this helps,

    Anthony

  • Nora 28 posts 97 karma points
    Dec 16, 2012 @ 10:23
    Nora
    0

    I've also been struggeling for a while with the cropped images using DAMP. Sometimes the solution is so easy - I simply did not realize that mediaCropper is the name of the image cropper property ... thanks at Arjan H. for the comment. Maybe it would be helpful to include this in the razor examples.

    Nora

  • Craig100 1136 posts 2523 karma points c-trib
    Apr 08, 2013 @ 22:56
    Craig100
    0

    Using non-MVC Razor I'm trying to cycle through child pages getting one of three images from each page and a particular crop. Using DAMP 2.5 (storing ID) and Umb 6.0.3.

                foreach (dynamic childPage in Model.Children.Where("Visible").OrderBy("publicationDate descending")) {
                   <div class="articleListItem">
                       <a href="@childPage.Url" title="@childPage.title">    

                      @foreach (dynamic image in Model.articleListImage) {                      
                           <img src="/imageGen.ashx?image=@DAMP_Helper.GetImageCropperUrl(image.Xml, "articleList")&amp;width=225&amp;height=103" width="225" height="103" alt="@image.Alt">                          
                       }</a><br>                

                       <a href="@childPage.Url" title="@childPage.title" class="@Model.bodyClass">@childPage.title</a><br>
                       <span class="newsDate">@childPage.publicationDate.ToString("dd MMMM yyyy")</span>
                   </div>
               }

    articleListImage is the propertyAlias of the DAMP control.
    articleList is the name of the crop required. 

    Everything appears on the page but the images! 

    I've tried @foreach (dynamic image in Model.articleListImage) and@foreach (dynamic image in childPage.articleListImage)to no avail.

    Any hints as to the correct syntax would be gratefully received.

    Craig

     

  • talerkk 2 posts 22 karma points
    Jul 16, 2013 @ 06:00
    talerkk
    0
    thx for the codes above provided by you guys .I have ever did the work in my way .check sample codes of image cropping
    using RasterEdge.Imaging.Basic;
    using RasterEdge.Imaging.Basic.Core;
    using RasterEdge.Imaging.Processing;
    using RasterEdge.Imaging.Basic.Codec;

    namespace RE__Test
    {
    public partial class Form1 : Form
    {
    public Form1()
    {
    InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e)
    {
    string fileName = "c:/Sample.png";

    REImage reImage = REFile.OpenImageFile(fileName);

    ImageProcessing.ApplyCrop(reImage, 80, 80, 500, 500);

    REFile.SaveImageFile(reImage, "c:/reimage.png", new PNGEncoder());
    }
    }
    }
  • Arjan H. 221 posts 457 karma points c-trib
    Jul 16, 2013 @ 10:47
    Arjan H.
    0

    I'm currently using the following helper class to fetch a crop:

    http://pastebin.com/raw.php?i=J6JFJtd2

    Save this code in UmbracoHelper.cshtml and place the file in your App_Code directory.

    Example of usage:

    var image = Model.MediaById(<mediaid>);
    var imageUrl = UmbracoHelper.GetMediaCropperUrl(image.mediaCropper, "<cropname>");

    if (imageUrl == String.Empty)
    {
    imageUrl = "/ImageGen.ashx?image=" + image.umbracoFile + "&crop=resize&width=<cropwidth>&height=<cropheight>&compression=90";
    }

    // Note: "mediaCropper" is the alias of the Image Cropper property I added to the Image media type.
  • Streety 358 posts 568 karma points
    Feb 21, 2014 @ 16:45
    Streety
    0

    I have spent an hour going through the Cultiv razor samples and trying to replicate the examples on another site.

     

    However the cultiv examples refer to a Data Type called DAMP 2.0 (Full Media).

    I have replicated the settings exactly on my site refering to a alias of mediaCropper in the display options.

     

    I can't figure where this value "media cropper" is referenced. Its not a Data type or a document type.

    Its not obvious how this all ties together.

     

    Also on the Cultiv site when editting a damp control there is a Crop tab which I don't get.

    Have I missed a step here?

     

    Any help would be appreciated.

     

     

    FOUND IT- IGNORE ME

     

     

Please Sign in or register to post replies

Write your reply to:

Draft