定制 pixelshelsinki/images 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pixelshelsinki/images

最新稳定版本:v1.0.3

Composer 安装命令:

composer require pixelshelsinki/images

包简介

Responsive Image component for WordPress

README 文档

README

Responsive Image component for WordPress. Handles retina sizes & different image shape for mobile.

  • Allows images to have normal & retina size
  • Allows images to have different mobile image in different aspect ratio
  • Automatically handles lazyload
  • Uses Picture tag for images & custom background style set for background images.

Install

composer require pixelshelsinki/images

Usage

Pixels Images consists of individual classes for image handling + a static factory for easily using them. Before using new image handlers you just have to register image sizes using the Factory class.

Register image sizes.

Declare your image sizes in your theme / plugin. Good spot would be 'init' action hook.

<?php

use Pixels\Components\Images\Factory as ImageFactory;

/**
 * Image sizes array
 * Pattern:
 *
 * NAME, WIDTH, HEIGHT, CROP, RETINA TRUE/FALSE
 *
 * @var array
 */
$sizes = array(
    'page-hero'        => array( 1100, 500, true, true ),
    'page-hero-mobile' => array( 375, 500, true, true ),
);

// Register sizes to image factory.
ImageFactory::add_image_sizes( $sizes );

/**
 * You can also optionally register css-style breakpoint for mobile / desktop.
 * Default is 576px.
 */
ImageFactory::add_breakpoint( '600px' );

Using responsive picture.

Usage in PHP:

<?php

use Pixels\Components\Images\Factory as ImageFactory;

$image_html = ImageFactory::responsive_image( $image_id, 'my_mobile_size', 'my_desktop_size', 'my alt text' );

echo $image_html;

Using responsive background.

Usage in PHP. Note that element with given CSS selector must exist in dom. Can be any valid css selector, like class or id.:

<?php

use Pixels\Components\Images\Factory as ImageFactory;

$image_html = ImageFactory::responsive_background( $image_id, 'my_mobile_size', 'my_desktop_size', '#my_html_element' );

echo $image_html;

Using with Twig / Timber.

Easiest way is to register the factory functions as Twig helper functions.

<?php

add_filter( 'get_twig', array( 'add_image_functions' ) );

function add_image_functions( $twig ) {
    // Responsive mage helper functions.
    $twig->addFunction( new \Timber\Twig_Function( 'responsive_image', '\\Pixels\\Components\\Images\\Factory::responsive_image' ) );
    $twig->addFunction( new \Timber\Twig_Function( 'responsive_background', '\\Pixels\\Components\\Images\\Factory::responsive_background' ) );

    return $twig;
}

统计信息

  • 总下载量: 24.36k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-01-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固