hcesrl/php-responsive-image-sizes
最新稳定版本:1.0.3
Composer 安装命令:
composer require hcesrl/php-responsive-image-sizes
包简介
Retrieve the correct sizes for a responsive image based on its intrinsic width and its width on screen
README 文档
README
Installation
composer require hcesrl/php-responsive-image-sizes
Usage
Please refer to the original javascript library documentation for further informations: https://github.com/HCESrl/responsive-image-sizes
Here is a basic example:
<?php
use Hcesrl\PhpResponsiveImageSizes\BaseSizes;
use Hcesrl\PhpResponsiveImageSizes\DeviceType;
use Hcesrl\PhpResponsiveImageSizes\ResponsiveImagesSizes;
require 'vendor/autoload.php';
var_dump(ResponsiveImagesSizes::getResponsiveSizes(DeviceType::All(), new BaseSizes(BaseSizesType::Granular())));
ResponsiveImagesSizes::getResponsiveSizes function accepts following parameters:
- $deviceType enum value: one of the available Enum DeviceType values (based on
marc-mabe/php-enumlibrary); - BaseSizes class instance: the constructor expects one of the available Enum BaseSizesType values (based on
marc-mabe/php-enumlibrary). If you chooseBaseSizesType::Custom()value, a second parameter is expected (see below); - $sourceImageWidth integer, default is 3220, see js library docs for further informations;
- $widthOnPage integer, default is 100, see js library docs for further informations;
- $topSize integer, default is 1920, see js library docs for further informations;
if you want to use a custom set of BaseSizes, you should declare an array that matches the following schema, and use it as second BaseSizes class constructor's argument:
[
'desktop' => [
-- values --
],
'tabletPortrait => [
-- values --
],
'smartphone' => [
-- values --
]
]
Example:
$customSizes = [
DeviceType::Desktop => [
1440,
1280,
1024
],
DeviceType::TabletPortrait => [
1024,
768
],
DeviceType::Smartphone => [
828,
750,
720,
640
]
];
var_dump(ResponsiveImagesSizes::getResponsiveSizes(DeviceType::All(), new BaseSizes(BaseSizesType::Custom(), $customSizes)));
Output sample:
(
[0] => 1024
[1] => 1280
[2] => 1440
)
统计信息
- 总下载量: 486
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-10-07