Coder Social home page Coder Social logo

kentico-michaelb / transformedimageselement Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yuriys-kentico/transformedimageselement

0.0 1.0 0.0 5.68 MB

Image Transformer Custom Element for Kentico Kontent.

License: MIT License

HTML 0.20% TypeScript 59.72% CSS 40.08%

transformedimageselement's Introduction

Image Transformer Custom Element for Kentico Kontent

This is a custom element similar to the Asset element, but it allows you to apply the Image Transformation API to any selected image.

ElementInAction

Setup

  1. Deploy the code to a secure public host.
    • See the Deploying section for a really quick option.
  2. Follow the instructions in the Kentico Kontent documentation to add the element to a content model.
    • The Hosted code URL is where you deployed to in step 1.
    • The Parameters {JSON} is a JSON object containing optional defaults. See the JSON parameters section for details.

Deploying

Netlify has made this easy. If you click the deploy button below, it will guide you through the process of deploying it to Netlify and leave you with a copy of the repository in your GitHub account as well.

Deploy to Netlify

JSON Parameters

All parameters are optional.

editorDefaultToPreview is a boolean that indicates whether to preview transformations in the editor by default.

editorDefaultCropType is a string defining the default crop mode. It must be one of the following: "box", "zoom", "frame".

editorDefaultResizeType is a string defining the default resize mode. It must be one of the following: "scale", "fit".

colorPickerDefaultColors is a string array containing the default colors in hexadecimal format, like ["#RRGGBBAA", "#4caf50"].

Example JSON parameters object:

{
  "editorDefaultToPreview": true,
  "editorDefaultCropType": "box",
  "colorPickerDefaultColors": ["#34aaffa4", "#4caf50"]
}

Saved Value

The value is a serialized JSON array of objects. Each object has the same shape and contains all of the original asset information as well as information for the transformations.

The transformedUrl property contains a URL to the image with the transformations applied. Alternatively, you can construct the transformation using the transform property. In that property, check whether any transform value is not -1.

Some properties, such as description and title may be empty or null if the image didn't have those values when the item containing the element was saved.

See the Kentico Kontent documentation for a description of the properties from the original image.

Example deserialized saved value with one image:

[
  {
    "id": "<asset_guid>",
    "description": "<asset_description>",
    "height": 322,
    "width": 500,
    "name": "<asset_name>",
    "title": null,
    "size": 44337,
    "type": "image/jpeg",
    "url": "<asset_base_url>",
    "transforms": {
      "crop": {
        "type": "box",
        "frame": {
          "wFloat": -1,
          "hFloat": -1
        },
        "box": {
          "xFloat": 0.47,
          "yFloat": 0.4969,
          "wFloat": 0.132,
          "hFloat": 0.2329
        },
        "zoom": {
          "xFloat": -1,
          "yFloat": -1,
          "zFloat": -1
        }
      },
      "resize": {
        "type": "fit",
        "scale": {
          "wFloat": -1,
          "hFloat": -1
        },
        "fit": {
          "wFloat": -1,
          "hFloat": -1
        },
        "devicePixelRatio": -1
      },
      "background": {
        "color": {
          "internalRgba": {
            "a": 0,
            "r": 0,
            "g": 0,
            "b": 0
          }
        }
      },
      "format": {
        "format": "JPG",
        "autoWebp": false,
        "lossless": null,
        "quality": 50
      }
    },
    "transformedUrl": "<asset_base_url>?rect=235,160,66,75&fm=jpg&q=50"
  }
]

transformedimageselement's People

Contributors

christopherjennings avatar yuriys-kentico avatar seruminar avatar

Watchers

James Cloos avatar

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.