Copied to clipboard

Flag this post as spam?

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


  • AmandaEly 123 posts 379 karma points
    Dec 12, 2014 @ 13:36
    AmandaEly
    0

    Unable to grab BlogLogo as TypedMedia

    Hi,

    I am integrating my blog into a site style which requires my images to fit in a certain space. Elsewhere I am using Umbraco.TypedMedia and GetCropUrl to achieve this. 

    My attempt to do something similar on the Master page (or via a macro) looks like this:

    var featureImage = Umbraco.TypedMedia(Model.BlogLogo);

    var imageUrl = featureImage.GetCropUrl(height: 600, width: 1200, imageCropMode: ImageCropMode.Crop);

    This crashes with 

    Compiler Error Message: CS0234: The type or namespace name 'TypedMedia' does not exist in the namespace 'Umbraco' (are you missing an assembly reference?)

    The same happens in a macro, if I try it that way.I know that the BlogLogo is from an imagecropper, so there must be a way to make this work, if I can get the references right.

    Any ideas?

  • Alex Skrypnyk 6131 posts 23950 karma points MVP 7x admin c-trib
    Dec 12, 2014 @ 22:24
    Alex Skrypnyk
    1

    Hi Amanda,

    Did you see that article ?

    http://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/

    Try like that :

    var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
    var media = umbracoHelper.TypedMedia(Model.BlogLogo);
    

    Thanks, Alexander

  • AmandaEly 123 posts 379 karma points
    Dec 13, 2014 @ 11:35
    AmandaEly
    0

    Thanks Alexander,

    I will try this but I have my doubts. Trouble is that the Articulate plugin (I believe) only gives me the url of the image and not the whole object. I'll report back soon!

     

    Amanda

  • Shannon Deminick 1524 posts 5269 karma points MVP 2x
    Dec 15, 2014 @ 02:17
    Shannon Deminick
    0

    The blog logo isn't a media node, it's just a property on the articulate root node.

    TypedMedia = get's a media item in the media tree TypeContent = get's a content item in the content tree

    Both return IPublishedContent

    The GetCropUrl method is an extension method on IPublishedContent.

    The Articulate.Models.IMasterModel contains a property called RootBlogNode which is of type IPublishedContent. Therefore you can use that:

    Model.RootBlogNode.GetCropUrl(.... )

    one of the values you can pass in to GetCropUrl is the property name, so use the property name for the logo.

  • Shannon Deminick 1524 posts 5269 karma points MVP 2x
    Dec 15, 2014 @ 02:18
    Shannon Deminick
    0

    Also, GetCropUrl is an extension method on string as well, so you can just do this:

    Model.BlogLogo.GetCropUrl(...)

  • AmandaEly 123 posts 379 karma points
    Dec 15, 2014 @ 13:34
    AmandaEly
    0

    Ahh. Now that all sounds good. I have tried the UmbracoHelper. Very useful, thank you. I shall also have a go at the various ways of getting a CropUrl.

  • AmandaEly 123 posts 379 karma points
    Dec 16, 2014 @ 13:01
    AmandaEly
    0

    I have added an image (articulate crop) to ArticulatePost called Post Image. How would I retrieve that using, say, Model.BlogArchiveNode?

     umbracohelper.Field("postImage"); gives me an htmlstring (of a complex src string to put in an img tag). Of course that is not the way to retrieve typed media. But umbracohelper.TypedMedia("postImage") returns null. I tried using the string to return typed media but that gave an exception. I think my solutions are too complicated. 

  • Shannon Deminick 1524 posts 5269 karma points MVP 2x
    Dec 24, 2014 @ 02:46
    Shannon Deminick
    0

    On a blog post page, Model = PostModel

    https://github.com/Shazwazza/Articulate/blob/master/Articulate/Models/PostModel.cs

    PostModel inherits from: MasterModel

    https://github.com/Shazwazza/Articulate/blob/master/Articulate/Models/MasterModel.cs

    which implements the standard IPublishedContent

    therefore you can do anything with Model that you can do with IPublishedContent and work with it the normal Umbraco way, example:

     @(Model.GetPropertyValue<string>("postImage"))
    

    which will return the JSON string stored for the crop. Just like i mentioned above, you can use the GetCropUrl extension method on a string, so you can just do:

     @(Model.GetPropertyValue<string>("postImage").GetCropUrl(....))
    

    I'll try to re-iterate: using TypedMedia = getting media from the media section, it has nothing to do with getting an image or any other property from the current document.

  • AmandaEly 123 posts 379 karma points
    Jan 20, 2015 @ 10:06
    AmandaEly
    0

    Model.GetPropertyValue("postImage").GetCropUrl(height: 600, width: 1200, imageCropMode: ImageCropMode.Crop);

    gets me

    "{\r\n  \"focalPoint\": {\r\n    \"left\": 0.47290640394088668,\r\n    \"top\": 0.31666666666666665\r\n  },\r\n  \"src\": \"/media/1040/beggar.jpg\",\r\n  \"crops\": []\r\n}?mode=crop&width=1200&height=600"

    Which I cannot use.

    I have used JsonConvert to get at the src part but no further. GetCropUrl just isn't doing the right thing here, in contrast to your own List.cshtml where BlogLogo is directly part of the model.

    I've spent all day on this. Starting to think it might work if I use the second override of GetCropUrl: Model.GetCropUrl("postImage", preferFocalPoint=true) and so on.

  • Shannon Deminick 1524 posts 5269 karma points MVP 2x
    Jan 21, 2015 @ 00:02
    Shannon Deminick
    0

    Model.GetPropertyValue("postImage") returns typeof 'object', and there's no extension method for GetCropUrl on 'object' so seems strange that that is working at all.

    As noted above, try:

     @(Model.GetPropertyValue<string>("postImage").GetCropUrl(....))
    
  • AmandaEly 123 posts 379 karma points
    Jan 21, 2015 @ 07:31
    AmandaEly
    0

    So sorry: I am using that format (I can't have checked my post very well).

    Model.GetPropertyValue<string>("postImage").GetCropUrl(...)  using height and width parameters retunrs the unchanged Json string .

  • AmandaEly 123 posts 379 karma points
    Jan 22, 2015 @ 19:13
    AmandaEly
    0

    Please forgive me, especially Shannon. 

    croppedUrl = Model.GetCropUrl(width:1200, height: 600, propertyAlias:"postImage", cropAlias:null,imageCropMode:ImageCropMode.Crop, preferFocalPoint:true );

    works perfectly and does not require any special helper objects or any twisting my code in knots. So many ways to skin a cat but only one is correct. Thanks for your help, I mean it.

  • Shannon Deminick 1524 posts 5269 karma points MVP 2x
    Jan 23, 2015 @ 06:41
    Shannon Deminick
    0

    glad you got the result you needed! Still not sure why the string extension is not working for you, i haven't had time to try to reproduce your outcome.

Please Sign in or register to post replies

Write your reply to:

Draft