Copied to clipboard

Flag this post as spam?

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


  • Thomas Beckert 193 posts 469 karma points
    Aug 27, 2014 @ 12:40
    Thomas Beckert
    0

    Access crop URL from c#

    Hi,

    I want to get a crop url in my UmbracoApiController-Class. I iterate over the nodes by ContentService-Class and access the image-Value with content.GetValue("image"), returning the json-string with all the crop infos.

    But how do I get the crop-Url of a specific crop-alias?

    Best regards -

    Tom

  • Amalie Wowern 144 posts 273 karma points MVP c-trib
    Aug 27, 2014 @ 13:56
    Amalie Wowern
    0
    Umbraco.Media(content.GetValue("image")).GetCropUrl("yourCrop") 
    
  • Thomas Beckert 193 posts 469 karma points
    Aug 27, 2014 @ 14:04
    Thomas Beckert
    0

    Hi Amalie,

    thanks for the quick reply. But in Umbraco 7.1.4 there seems to be no Umbraco.Media anymore...

  • Amalie Wowern 144 posts 273 karma points MVP c-trib
    Aug 27, 2014 @ 14:07
    Amalie Wowern
    0

    I have used it in umbraco 7.1.4

  • Amalie Wowern 144 posts 273 karma points MVP c-trib
    Aug 27, 2014 @ 14:17
  • Thomas Beckert 193 posts 469 karma points
    Aug 27, 2014 @ 15:10
    Thomas Beckert
    0

    Ok, there seems to be a bug in the 7.1.6 - I do not get the crop with GetCropUrl.

    I get this URL and as you see, the picture is not 800x800:

    http://secondhair.sitepoint.de/media/1013/bm_city_kiew-champagne-mix_5885.jpg?crop=0.0000000000000001263187085796,0.029629629629629631,0,0.3037037037037037&cropmode=percentage&width=800&height=800&rnd=130536255070000000

    I will do a bug-report.

     

  • Amalie Wowern 144 posts 273 karma points MVP c-trib
    Aug 27, 2014 @ 15:19
    Amalie Wowern
    0

    Did you create the crop after uploading the image? If you did, go to the media folder and re-save the picture.

  • Thomas Beckert 193 posts 469 karma points
    Aug 27, 2014 @ 16:00
    Thomas Beckert
    0

    Ok. My mistake, I had to add this to the web.config:

    httpModule:

    <add name="ImageProcessorModule" type="ImageProcessor.Web.HttpModules.ImageProcessingModule, ImageProcessor.Web"/>

    And in system.webServer/modules add:

     

    <add name="ImageProcessorModule" type="ImageProcessor.Web.HttpModules.ImageProcessingModule, ImageProcessor.Web"/>

     

    Anyway, I created a cropper in the content-section, not in the media-section.

    If I call the getCropUrl-Function within my template, all of these calls work:

    <img src='@CurrentPage.GetCropUrl("bild", "klein")' />
    <img src='@Umbraco.Content(3192).GetCropUrl("bild", "klein")' />
    <img src='@Model.Content.GetCropUrl("bild", "klein")' />

    But if I call it from my C# Code in my UmbracoApiController, it does not return the crop-Url, but the path to the node:

     Umbraco.Content(3192).GetCropUrl("bild", "klein") returns:
    /dening-hair-company/peruecken/bianca/?mode=pad&rnd=130536278570000000

    instead of:
    /media/1916/bianca_terracotta-mix-root_0042011_01_2400x3600fb94.jpg?crop=0,0.048888888888888891,0,0.28444444444444444&cropmode=percentage&width=300&height=300&rnd=130536278570000000 

    as it does in the template-code. 

  • Thomas Beckert 193 posts 469 karma points
    Aug 27, 2014 @ 17:43
    Thomas Beckert
    0

    Ok, if I call it this way, it works (why ever):

    var contentCurrent = Umbraco.Content(3192);
    string cropURL = 
    contentCurrent.GetCropUrl("bild", "klein");

    Thanks for your support though!

Please Sign in or register to post replies

Write your reply to:

Draft