定制 addequatte/photo-box-centering 二次开发

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

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

addequatte/photo-box-centering

最新稳定版本:v1.0

Composer 安装命令:

composer require addequatte/photo-box-centering

包简介

Allows you to center the photo on a given area, such as the coordinates of the face. You can specify the percentage of face filling in the final photo, which you can set yourself.

README 文档

README

Allows you to center the photo on a given area, such as the coordinates of the face. You can specify the percentage of face filling in the final photo, which you can set yourself.

Installation

composer require addequatte/photo-box-centering

For example

/**
 * public/index.php
 */
use Addequatte\PhotoBoxCentering\Data\PositionedBox;
use Addequatte\PhotoBoxCentering\Data\TranslatePlan;
use Addequatte\PhotoBoxCentering\Service\PhotoTranslator;

require_once __DIR__ . '/../vendor/autoload.php';

$photoUrl = 'data:image/png;base64, ' . base64_encode(file_get_contents(__DIR__ . '/pic.jpg'));
$photoWidth = 1280;
$photoHeight = 720;

$targetWidth = $_GET['w'] ?? 200;
$targetHeight = $_GET['h'] ?? 200;

$targetBoxPercent = $_GET['p'] ?? 40;

$translatePlan = new TranslatePlan($photoWidth, $photoHeight, $targetWidth, $targetHeight, $targetBoxPercent);

// Face coordinates on photo
$positionedBox = new PositionedBox(635, 100, 785, 315);

$photoTranslator = new PhotoTranslator();

$translatePhoto = $photoTranslator->center($translatePlan, $positionedBox);

$translateX = $translatePhoto->translateX();
$translateY = $translatePhoto->translateY();

$scale = $translatePhoto->scale();

include(__DIR__ . '/index.phtml');
<div class="photo_box" 
     style="overflow: hidden;
        width:{{ targetBoxWidth }}px;
        height:{{ targetBoxHeight }}px;" >
    <img 
            src="{{ photoUrl }}" 
            style="min-width:100%; 
            min-height:100%; 
            width:{{ scale }}%;
            transform:translate({{ translateX }}%, {{ translateY }}%)">
</div>

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-29