nambu-ch/pimcore-image-loader 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

nambu-ch/pimcore-image-loader

Composer 安装命令:

composer require nambu-ch/pimcore-image-loader

包简介

Pimcore 10.x, 11.x Load images depending on box size

关键字:

README 文档

README

Pimcore 10.x bundle to automate the minification of images inside a webpage.

Automatically generates all needed thumbnails and loads them in relation to the width of the surrounding html-element. The smallest image will be loaded as the default. Default image sizes are [320, 480, 768, 1024, 1280, 1920].

Install and Enable

composer require nambu-ch/pimcore-image-loader
php bin/console pimcore:bundle:enable ImageLoaderBundle

Dependencies

This library needs Bootstrap and jQuery to work.

Get rid of bootstrap

As an easy fix you can add the following css definition to your own style, so you don't need to include bootstrap:

.img-fluid {
    max-width: 100%;
    height: auto;
}

Usage

Load js file inside your layout.

$view->headScript()->appendFile('/bundles/imageloader/js/imageloader.js');
{% do pimcore_head_script().appendFile(asset('/bundles/imageloader/js/imageloader.js')) %}

There is now a version without the dependency of jquery at /bundles/imageloader/js/imageloader-vanilla.js.

Example

{{ imageloader("image", { width: 300 }) }}
//or
{% if editmode %}
    {{ pimcore_image("image", { width: 300 }) }}
{% else %}
    {% if not pimcore_image("image").isEmpty() %}
        {{ imageloader(pimcore_image("image"), { options... })|raw }}
    {% endif %}
{% endif %}
// or
{% set asset = pimcore_asset(2) %}
{{ imageloader(asset, { options... })|raw }}

Force imageloader to recalculate

The imageloader listens to the window resize event and automaticaly loads the best image, but sometimes images appear and need an manual recalculation of the best image size, for example when an accordion opens. In combination with the bootstrap event, this is done like this:

$('.accordion-collapse').on('show.bs.collapse', function () {
    var images = $(this).find(".image-loader");
    setTimeout(function () {
        images.imageLoader('onResized');
    }, 1);
}).on('shown.bs.collapse', function () {
    $(this).find(".image-loader").imageLoader('onResized');
});

Configuration

Name Type Description
cache_buster.disabled boolean It takes the modification date of the image asset to refresh cache if needed. (enabled by default)
lazyloading boolean lazyloading adds the loading="lazy" to the image tag.
image_loader:
  cache_buster:
    disabled: true
  lazyloading: false

Available options

Following options are available:

Name Type Description
isBackgroundImage boolean Set to true to load image as css background, instead of img-tag.
imageCssClass string A CSS class to apply to the image.
thumbnailNames array List of size => thumbnail-names to generate the different sizes. e.g. [ 320 => 'thumb-small', 1024 => 'thumb-big' ]
sizeSelector string jQuery CSS selector to a html element which will be used for determining the size. e.g. '.some-element'
widths array List of thumbnail widths to override default sizes e.g. [ 480, 1024, 1920 ]
sizesOptions array List of options e.g. [ 480 => [ 'size' => 480, 'imageTag' => $view->image('image-480') ] ]
altText string Alt-Text of the image.
setImageSize boolean Set width and height attributes on img element.
thumbnail string Thumbnail-Name from Pimcore configuration.
emptyImageThumbnail string or Asset\Image Path to an Image or a Pimcore Asset\Image which is shown at start before imageloader determines the fitting thumbnail
lazyLoad boolean Enable lazy loading via IntersectionObserver (deprecated)
disableCacheBuster boolean Disable Cache Buster

Advanced usage

imageCssClass Option can be used to switch from background image to img-tag, set isBackgroundImage to true and define imageCssClass => 'd-block d-md-none'. If so the img-tag is shown on small sizes and a background from md-breakpoint upwards.

Using thumbnails with media queries

If the option thumbnail is set and the configuration has media queries, those are used for loading the image. Media queries are only used with their px value. So it doesn't matter if you have set min-with or max-width. It will always use the px as max-width. This option can be used together with isBackgroundImage, imageCssClass, sizeSelector and altText.

nambu-ch/pimcore-image-loader 适用场景与选型建议

nambu-ch/pimcore-image-loader 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 498 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 10 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「image」 「pimcore」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 nambu-ch/pimcore-image-loader 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nambu-ch/pimcore-image-loader 我们能提供哪些服务?
定制开发 / 二次开发

基于 nambu-ch/pimcore-image-loader 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2019-10-29