clippings/fluid-gallery

按百分比排列图片

0.4.0 2020-02-11 10:33 UTC

This package is auto-updated.

Last update: 2024-08-25 19:37:26 UTC


README

Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version

按百分比排列图片

安装

通过composer安装

composer require clippings/fluid-gallery

使用方法

概念上,您将图片(或视频)堆叠到一个ItemGroup中,然后逐行使用自定义尺寸逻辑提取。

$gallery = new ItemGroup([
    new Item(100, 200, 'http://example.com/1.jpg'),
    new Item(200, 100, 'http://example.com/2.jpg'),
    new Item(100, 100, 'http://example.com/3.jpg'),
    new Item(300, 200, ['url' => 'http://example.com/video.mov', 'type' => 'video']),
]);

$gallery->setMargin(15);

// extract some of the images into another group
$group = $gallery->extract(function ($group) {

    // The returned items are removed from the parent gallery
    return $group
        // get only images with text urls
        ->filter(function (Item $item) {
            return is_string($item->getContent());
        })
        // set the hight of all the images to 50, preserving the aspect ratios
        ->setHeight(50)
        // Get a slice of the images, arranged horizontally, no wider than 200 pixels
        ->horizontalSlice(200)
        // Scale horizontally arranged images to exactly 200, keeping aspect ratios
        ->scaleToWidth(200);
});

foreach ($group as $item) {
    echo $item->getContent();
}

// Get the remaining items
echo $gallery[0]->getContent()['url'];

许可证

版权(c)2015,Clippings Ltd. 由Ivan Kerin开发

在BSD-3-Clause许可证下,请参阅LICENSE文件。