人工制造/smart-media

HM Cloud 的智能媒体功能

安装次数: 155,607

依赖项: 2

建议者: 0

安全性: 0

星标: 82

关注者: 27

分支: 7

开放问题: 23

类型:wordpress-plugin

0.5.4 2024-04-22 12:40 UTC

This package is auto-updated.

Last update: 2024-09-21 06:44:25 UTC


README

为 WordPress 提供更智能的媒体功能。

此插件中的一些功能可以独立运行,但有些功能旨在增强我们使用的现有工具,例如 Tachyon

功能

对齐媒体库

默认情况下,媒体库显示正方形缩略图,这可能会使查找正确的图像变得困难。此功能使缩略图保持原始的宽高比,类似于 Flickr 的 UI。

要禁用此功能,请添加以下内容

<?php
add_filter( 'hm.smart-media.justified-library', '__return_false' );

图片编辑器

此功能覆盖了内置的 WordPress 图片编辑体验,并允许您控制单个缩略图的裁剪。还有一些用户体验改进,意味着进行编辑所需的点击次数更少。

要禁用此功能,请添加以下内容

<?php
add_filter( 'hm.smart-media.cropper', '__return_false' );

图片裁剪 UI 提供了对以下过滤器的支持,用于根据当前选择更新 Gutenberg 块属性

  • smartmedia.cropper.updateBlockAttributesOnSelect.<块名称>
  • smartmedia.cropper.selectSizeFromBlockAttributes.<块名称>

在上面的过滤器中,<块名称> 应替换为点分隔的块名称版本,例如 core/image 变为 core.image。默认情况下,核心图片块属性已映射。

将选定的图像映射到块属性

addFilter(
  'smartmedia.cropper.updateBlockAttributesOnSelect.core.image',
  'smartmedia/cropper/update-block-on-select/core/image',
  /**
   * @param {?Object} attributes  The filtered block attributes. Return null to bypass updating.
   * @param {Object} image  The image data has the following shape:
   *   {
   *     name: <string>,  The image size name
   *     url: <string>,  The URL for the sized image
   *     width: <int>,  The width in pixels
   *     height: <int>,  The height in pixels
   *     label: <string>,  The human readable name for the image size, only present for user selectable sizes
   *     cropData: <?object>,  Null or object containing x, y, width and height properties
   *   }
   */
  ( attributes, image ) => {
    // Only user selectable image sizes have a label so return early if this is missing.
    if ( ! image.label ) {
      return attributes;
    }

    return {
      sizeSlug: image.size,
      url: image.url,
    };
  }
);

根据选定的块属性更新裁剪 UI 的选定大小

addFilter(
  'smartmedia.cropper.selectSizeFromBlockAttributes.core.image',
  'smartmedia/cropper/select-size-from-block-attributes/core/image',
  /**
   * @param {?String} size  The image size slug.
   * @param {Object} block  The currently selected block.
   */
  ( size, block ) => {
    return size || block.attributes.sizeSlug || 'full';
  }
);

该函数接受 2 个参数

  • block:要映射属性的块名称
  • callback:一个函数,它接受图像 size 名称、包含 urlwidthheight、裁剪数据和图像大小标签的图像对象,以及最后是完整的 attachment 数据对象。

回调应返回一个对象或 null。传递 null 将防止更新当前选定的块。

路线图

计划的功能包括

  • 重复图像检测和合并
  • EXIF 数据编辑器

贡献

首先,感谢您使用此插件,并感谢您做出贡献!

要开始,请查看 贡献文档