Git Product home page Git Product logo

imageresizer.plugins.episerverblobreader's Introduction

Build status

ImageResizer.Plugins.EPiServerBlobReader

Nothing much to describe here :) Just install NuGet package and it will register EPiServer Blob reader plugin for ImageResizer in order to serve and process images from EPiServer Media folders by ImageResizer.

Breaking Changes (starting from v6.0)

If you use fluent API to resize the image and pass in null, string.Empty or ContentReference.EmptyReference you will get ArgumentNullException exception.

Render Image in Markup

Most convenient way to render image in markup would be use HtmlHelper extension method:

@using ImageResizer.Plugins.EPiServer

<img src="@Html.ResizeImage(Model.CurrentPage.MainImage, 100, 100)" />

This will make sure that markup for visitors would be (assuming that image is png):

<img src="/.../image.png?w=100&h=100">

And also for the edit mode it would be generated something like this:

<img src="/.../image.png,,{CONTENT-ID}?epieditmode=False&w=100&h=100">

ResizeImage returns back UrlBuilder type, so you can fluently chain any additional paramters if needed:

<img src="@Html.ResizeImage(Model.CurrentPage.MainImage, 100, 150).Add("gradient", "true").Add("bgcolor", "red)" />

Render Image Markup (Fluent)

You can also use some basic fluent api support as well:

<img src="@Html.ResizeImage(CurrentPage.MainImage).Width(200)
                                                  .Height(200)
                                                  .Scale(ScaleMode.Both)
                                                  .FitMode(FitMode.Crop)" />

Render Image Markup with Fallback (Fluent)

If you need to fallback to other image in cases when given ContentReference is empty (and don't want to check for null or ContentReference.EmptyReference yourself) you can use resize image with fallback:

<img src="@Html.ResizeImageWithFallback(CurrentPage.MainImage, "/no-image.jpg").Width(200).Height(200).Scale(ScaleMode.Both).FitMode(FitMode.Crop)" />

Render Picture Element

This is pretty simple as well.

  1. We need to define picture profile. Profile is metadata how to render <picture> element.
public static PictureProfile SampleImage =
    new PictureProfile
    {
        SrcSetWidths = new[] { 480, 768, 992, 1200 },
        SrcSetSizes = new[]
        {
            "50vw",
        },
       DefaultWidth = 992
    };

Here we can specify couple of properties to customize element:

  • Source set sizes (SrcSetSizes) - this regulates image size for various media conditions.
  • Source set widths (SrcSetWidths) - this regulates various image sizes (resized by width specified here). Used to generate srcset attribute.
  • Default width (DefaultWidth) - what is default width of the image. This is for old-school browsers those have no clue about <picture> element existence.
  1. Call actual rendering method
@Html.ResizePicture(Model.CurrentPage.MainImage, PictureProfiles.SampleImage)
  1. Code above generates following markup:
<picture>
    <source sizes="50vw"
            srcset="/globalassets/batman.jpg?w=480 480w,
                    /globalassets/batman.jpg?w=768 768w,
                    /globalassets/batman.jpg?w=992 992w,
                    /globalassets/batman.jpg?w=1200 1200w">
    <img alt="" src="/globalassets/batman.jpg?w=992">
</picture>

More info about how to render picture element - here.


Happy imaging!

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.