Skip to content

OwainWilliams/OC.MediaColourFinderV2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Media Colour Finder V2

Downloads NuGet GitHub license

Add this property editor to an Image Media Type in Umbraco to automatically extract colour information from your images.

Installation

Add the package to an existing Umbraco website (v15+) from nuget:

dotnet add package OC.MediaColourFinderV2

How to use

Once the package is installed, you will have a new property editor which should then be added to a Media Type of "Image". When you upload an image, you can select a focal point (optional) and the package will then calculate the average color, brightest color, opposite colour and text colour. If no focal point is set, the colours are calculated from the entire image.

Media Colour Finder Demo

The calculated colours are then available as properties on the media item, which can be accessed in your views. For example, if you call the new property on the media type "colour finder" it will have an alias colourfinder and can be accessed like :


@{
    var colours = (Model?.Image?.Content as Image)?.ColourFinder;
}

@if (colours != null)
{
    @colours.Average <span style="background-color: @colours.Average;">Average</span>
    <br />
    @colours.Brightest <span style="background-color: @colours.Brightest;">Brightest</span>
    <br />
    @colours.TextColour <span style="background-color: @colours.TextColour;">TextColour</span>
    <br />
    @colours.Opposite <span style="background-color: @(string.IsNullOrEmpty(colours.Opposite) ? "#fff" : colours.Opposite);">Opposite</span>
}



The output will be in HEX format, e.g. #FFFFFF which can then be used in your CSS.

Contributing

Contributions to this package are most welcome! Please feel free to fork the repository and submit a pull request with your changes.

Acknowledgments

Thanks to Lee Kelleher for his help with the initial thought process and build of this new version. #h5yr

About

An Umbraco 17 package that allows you to automatically extract colour information from your images. This can then be use as hex values on the frontend

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project

Contributors