承接 mediashowroom/php-svg 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

mediashowroom/php-svg

Composer 安装命令:

composer require mediashowroom/php-svg

包简介

Read, edit, write, and render SVG files with PHP

关键字:

README 文档

README

Build Status Code Climate

This is a vector graphics library for PHP, which surely is a broad specification. That is due to the fact that the goal of this project is to offer features in three different, big areas:

  • Generating SVG images from PHP code and outputting them, either into XML strings or into files.
  • Loading and parsing XML strings into document trees that can be easily modified and then also turned back into strings.
  • Transforming parsed or generated document trees into raster graphics, like PNG.

Contributing

These tasks will take a lot of time and effort, so you are welcome to contribute if this is a project you are interested in.
In case you decide to contribute, please honor these things:

  1. External libraries shall not be used.
  2. Please set your editor to use 4 spaces for indentation. In general, it would be good to follow the existing code style for consistency.
  3. Source files must end with a newline character.
  4. By contributing code, you agree to license that code under the MIT license to this project.

Installation

Composer (recommended)

This package is available through Composer/Packagist:

$ composer require meyfa/php-svg

Manual

Download this repo, or the latest release, and put it somewhere in your project. Then do:

<?php
require_once __DIR__.'/<path_where_you_put_it>/autoloader.php';

The rest works exactly the same as with Composer, just without things like nice version management.

Getting Started

Creating an image

The following code generates an SVG with a blue square, sets the Content-Type header and echoes it:

<?php

use SVG\SVGImage;
use SVG\Nodes\Shapes\SVGRect;

// image with 100x100 viewport
$image = new SVGImage(100, 100);
$doc = $image->getDocument();

// blue 40x40 square at (0, 0)
$square = new SVGRect(0, 0, 40, 40);
$square->setStyle('fill', '#0000FF');
$doc->addChild($square);

header('Content-Type: image/svg+xml');
echo $image;

Rasterizing

To convert an instance of SVGImage to a PHP/GD image resource, or in other words convert it to a raster image, you simply call toRasterImage($width, $height) on it. Example:

<?php

use SVG\SVGImage;
use SVG\Nodes\Shapes\SVGCircle;

$image = new SVGImage(100, 100);
$doc = $image->getDocument();

// circle with radius 20 and green border, center at (50, 50)
$doc->addChild(
    (new SVGCircle(50, 50, 20))
        ->setStyle('fill', 'none')
        ->setStyle('stroke', '#0F0')
        ->setStyle('stroke-width', '2px')
);

// rasterize to a 200x200 image, i.e. the original SVG size scaled by 2
$rasterImage = $image->toRasterImage(200, 200);

header('Content-Type: image/png');
imagepng($rasterImage);

Loading an SVG

You can load SVG images both from strings and from files. This example loads one from a string, moves the contained rectangle and echoes the new SVG:

<?php

use SVG\SVGImage;

$svg  = '<svg width="100" height="100">';
$svg .= '<rect width="50" height="50" fill="#00F" />';
$svg .= '</svg>';

$image = SVGImage::fromString($svg);
$doc = $image->getDocument();

$rect = $doc->getChild(0);
$rect->setX(25)->setY(25);

header('Content-Type: image/svg+xml');
echo $image;

For loading from a file instead, you would call SVGImage::fromFile($file). That function supports local file paths as well as URLs.

mediashowroom/php-svg 适用场景与选型建议

mediashowroom/php-svg 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.69k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 02 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 mediashowroom/php-svg 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-02-05