Code Monkey home page Code Monkey logo

our.umbraco.picture's Introduction

Our.Umbraco.Picture

A extension library for generating HTML5 Picture element with ease.

Installation

PM > Install-Package Our.Umbraco.Picture

Download picturefill.min.js from https://github.com/scottjehl/picturefill and place in the ~/scripts/ folder of your umbaco solution.

Include this in the header:

@Html.RequiresJs("~/Scripts/picturefill.min.js", 101);

How to

There a multiple ways to use this.

Basic

This way you can have multiple images, and sources. Lets say a cat, swapped with a tiger, if width > 480px

@{
    IPublishedContent cat = Umbraco.TypedMedia(1000);
    IPublishedContent tiger = Umbraco.TypedMedia(1001);
    var picture = Umbraco.Picture()
        .Source("(min-width:480px)", tiger.GetCropUrl(768, 300))
        .Source("(min-width:320px)", cat.GetCropUrl(480, 300) + " x1", cat.GetCropUrl(960, 600) + " x2")
        .Srcset(cat.GetCropUrl(768, 300))
        .Attr("class", "img-responsive")
        .Alt("Cat becomes tiger");

    @Html.RenderPicture(picture);
}

HTML

<picture class="img-responsive">
    <!--[if IE 9]><video style="display: none;"><![endif]-->
    <source media="(min-width:480px)" 
            srcset="/media/1001/tiger.jpg?width=768&height=300&mode=crop">
    <source media="(min-width:320px)" 
            srcset="/media/1000/cat.jpg?width=480&height=300&mode=crop 1x, 
                    /media/1000/cat.jpgwidth=960&height=600&mode=crop 2x">
    <!--[if IE 9]></video><![endif]-->
    <img src="data:image/gif;base64,R0lGODlhAQABAAAAADs=" srcset="" alt="Cat becomes tiger" /> 
</picture>

Typed

Simple but effective.

@{
    IPublishedContent media = Umbraco.TypedMedia(1000);
    var picture = Umbraco.Picture(media)
        .Source("(min-width:992px)", 1200, 300, 1.0, 2.0)
        .Source("(min-width:768px)", 992, 300, 1.0, 2.0)
        .Source("(min-width:480px)", 768, 300, 1.0, 2.0)
        .Source("(min-width:320px)", 480, 300, 1.0, 2.0)
        .Srcset(768, 300)
        .Attr("class", "img-responsive")
        .Alt(media.GetPropertyValue<string>("alt", ""));

    @Html.RenderPicture(picture);
}

HTML

<picture class="img-responsive">
    <!--[if IE 9]><video style="display: none;"><![endif]-->
    <source media="(min-width:480px)" 
            srcset="/media/1001/image.jpg?width=1200&height=300&mode=crop x1,
                    /media/1001/image.jpg?width=2400&height=600&mode=crop x2">
    ...
    <!--[if IE 9]></video><![endif]-->
    <img src="data:image/gif;base64,R0lGODlhAQABAAAAADs=" srcset="/media/1001/image.jpg?width=768&height=300&mode=crop" alt="..." /> 
</picture>

In-action:

References

Known Issues

none

our.umbraco.picture's People

Contributors

herpoelaertw avatar rasmuseeg avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

herpoelaertw

our.umbraco.picture's Issues

img src missing quotes

<img src=data:image/gif;base64,R0lGODlhAQABAAAAADs= srcset="/media/1004/uddfb_logo_bred.png?anchor=center&mode=crop&width=200&rnd=131159977680000000" alt="" />

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.