承接 pixelfactory/psd-php 相关项目开发

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

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

pixelfactory/psd-php

Composer 安装命令:

composer require pixelfactory/psd-php

包简介

Library for reading psd file

README 文档

README

PSD-PHP

Logo

Library for reading psd file

Installation

composer require pixelfactory/psd-php

Usage

Create an instance of the 'Psd' class by passing the file path.

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

$psd = new \Psd\Psd('./image.psd');

Then you have two ways to use the library, 'simple' and 'professional'
Simple - way is suitable for those who are not familiar with the structure of the psd file and just want to get the necessary information
Professional - way can be used by more experienced developers to get access to a specific part of the file

Simple

Getting file sizes

$psd = new \Psd\Psd('./image.psd');
$psdSimpleMethods = $psd->getShortcuts();

echo $psdSimpleMethods->getWidth();    // Print file width
echo $psdSimpleMethods->getHeight();   // Print file height

Saving an image

$psd = new \Psd\Psd('./image.psd');
$psdSimpleMethods = $psd->getShortcuts();

var_dump($psdSimpleMethods->savePreview('./out.png')); // Print 'true' if file be saved

Working with the layers tree

// TODO
[Layers tree] Moving from directories
// TODO
[Layers tree] Getting information about a layer
// TODO
[Layers tree] Saving a layer image
// TODO

Professional

The psd class has the same structure as the psd file.

Name Method Examples
File header getHeader Link
Color mode data
Image resources getResources Link
Layer and mask information getLayers Link
Image data getImage Link

1 - 'Color mode data' has no method because it is skipped and not processed by the library. This should not affect the work with most images because they have the "rgb" or "cmyk" color mode. This section is used only in the "Indexed" or "Duotone" color mode.

Header data

You can call the 'getHeader' method to get class implements HeaderInterface what contains methods for all fields image header section.

File header section HeaderInterface methods
Signature
Version getVersion
Reserved -
Channels getChannels
height getRows (Alias: getHeight)
width getCols (Alias: getWidth)
Depth getDepth
Color mode getMode (Convert mode number to text: modeName)
- parse
- getNumPixels
- getChannelLength
- getFileLength

Example:

echo $psd->getHeader()->getMode();     // Return file mode (int)
echo $psd->getHeader()->modeName();    // Return file mode name
echo $psd->getHeader()->getChannels(); // Return file count channels

Image resources

Image resources section store additional information. Such as guides, etc.
The library is working with resources:

  • Guides(1032)
  • Layer Comps(1065)
  • Resolution Info(1005)

The full list of resources you can be found in the documentation

To find the necessary resource, you need to call the method getResources (this method return class what extends from ResourcesInterface).
Next, you can use the search by the resource name or resource id.

Example. Get guides:

/** @var \Psd\FileStructure\Resources\Resource\Guides\GuidesData[] $guides */
$guides = $psd
    ->getResources()
    ->getResourceById(\Psd\FileStructure\Resources\Resource\ResourceBase::RESOURCE_ID_GUIDES)
    ->getData();

foreach ($guides as $guide) {
    printf("%s - %s\n", $guide->getDirection(), $guide->getLocation()); // Result: 'vertical - 100'
}

Layer and mask information

// TODO

Image data

This section stores the image. You can get a class for exporting an image using the method getExporter.
Now is available only png class for export image:

/* @var Psd\Image\ImageExport\Exports\Png $exporter */
$exporter = $psd->getImage()->getExporter(\Psd\Image\ImageExport\ImageExport::EXPORT_FORMAT_PNG);

All exporters classes implements interface: ImageExportInterface
You can export the image to the Imagick class or save it.

/** @var Imagick $image */
$image = $exporter->export();
/** @var bool $status */ 
$status = $exporter->save('./out.png');

pixelfactory/psd-php 适用场景与选型建议

pixelfactory/psd-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 734 次下载、GitHub Stars 达 19, 最近一次更新时间为 2023 年 01 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 19
  • Watchers: 3
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-01-09