Giter Club home page Giter Club logo

zyx-widget-imagex's Introduction

ImageX

Latest Stable Version Latest Unstable Version Total Downloads License Code Climate Scrutinizer Code Quality

Widget for simple generating OpenGraph meta tags and Schema.org markdown for images ('X' stands for 'eXtended').

You may do absolutely nothing - OpenGraph meta tags and Schema.org markdown will be generated 'on-the-fly' from image properties (which you can still define like you do in Html::img()).

REQUIREMENTS

You should generally follow Yii 2 requirements. The minimum is that your Web server supports PHP 5.4.0.

INSTALLATION

Install via Composer

If you do not have Composer, you may install it by following the instructions at getcomposer.org.

Either run

php composer.phar require --prefer-dist zyx/widget-imagex "*"

or add

"zyx/widget-imagex": "*"

to the require section of your composer.json.

USAGE

Just add following string to your layout

use zyx\widgets\ImageX;

And call widget where the image is supposed to be instead of usual Html::img():

echo ImageX::widget([
                  'src' => 'http://static.yiiframework.com/css/img/logo.png',
                  'options' => ['width' => 280, 'height' => 60],
                  'og' => [],
                  'md' => ['div_class' => 'image_wrap']
                ]);

Note: only 'src' parameter is mandatory. Array of 'options' is the same you use for image options in Html::img(). If both 'og' (OpenGraph) and 'md' (schema.org) configuration arrays are empty - you may not declare them at all. You can to disable one of them (they are both enabled by default) - e.g. 'md' => ['enable' => false].

So, the result of example above should be something like this:

In the HEAD:

...
  <meta property="og:image" content="http://static.yiiframework.com/css/img/logo.png">
  <meta property="og:image:type" content="image/png">
  <meta property="og:image:width" content="280">
  <meta property="og:image:height" content="60">
...

In the BODY ('img' is wrapped in 'div' tag):

...
<div itemscope itemtype="http://schema.org/ImageObject" class="image_wrap">
  <img src="http://static.yiiframework.com/css/img/logo.png" width="280" height="60" alt="" itemprop="contentUrl" />
	<meta itemprop="width" content="280" />
	<meta itemprop="height" content="60" />
</div>
...

Properties like 'width' and 'height' set explicitly in 'og' and 'md' configuration arrays, passed to widget, have priority. If no such options were set, widget attempts to extract properties from image 'options' array.

So you can just call:

echo ImageX::widget([
                  'src' => 'http://static.yiiframework.com/css/img/logo.png',
                  'options' => ['width' => 280, 'height' => 60]
                ]);

like you called Html::img() with no additional options.

zyx-widget-imagex's People

Contributors

sdkiller avatar

Stargazers

Marcio Vale avatar

Watchers

James Cloos avatar  avatar  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.