定制 ycdev/paper-size 二次开发

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

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

ycdev/paper-size

Composer 安装命令:

composer require ycdev/paper-size

包简介

Paper Size constant and convert to inch/pixe

README 文档

README

A PHP class for managing paper formats and their conversions.

Installation

composer require ycdev/paper-size

Supported Paper Formats

ISO Formats

Format Dimensions (mm) Description
A0 841 × 1189 Largest standard ISO format
A1 594 × 841 Half of A0
A2 420 × 594 Half of A1
A3 297 × 420 Half of A2
A4 210 × 297 Standard paper size
A5 148 × 210 Half of A4
A6 105 × 148 Half of A5
A7 74 × 105 Half of A6
A8 52 × 74 Half of A7
A9 37 × 52 Half of A8
A10 26 × 36 Half of A9

B Series (ISO)

Format Dimensions (mm) Description
B0 1000 × 1414 Largest B series format
B1 707 × 1000 Half of B0
B2 500 × 707 Half of B1
B3 353 × 500 Half of B2
B4 250 × 353 Half of B3
B5 176 × 250 Half of B4
B6 125 × 176 Half of B5
B7 88 × 125 Half of B6
B8 62 × 88 Half of B7
B9 44 × 62 Half of B8
B10 31 × 44 Half of B9

C Series (ISO)

Format Dimensions (mm) Description
C0 917 × 1297 Largest C series format
C1 648 × 917 Half of C0
C2 458 × 648 Half of C1
C3 324 × 458 Half of C2
C4 229 × 324 Half of C3
C5 162 × 229 Half of C4
C6 114 × 162 Half of C5
C7 81 × 114 Half of C6
C8 57 × 81 Half of C7
C9 40 × 57 Half of C8
C10 28 × 40 Half of C9

US Formats

Format Dimensions (mm) Description
US Letter 216 × 279 Standard US paper size
US Executive 184 × 267 Executive size
US Government Letter 203 × 267 Government documents
US Quarto 229 × 279 Quarto size
US Foolscap Folio 216 × 330 Foolscap folio size
US Half Letter 140 × 216 Half of US Letter
US Junior Legal 140 × 216 Junior legal size

French Formats (AFNOR)

Format Dimensions (mm) Description
Cloche 300 × 400
Pot 310 × 400
Tellière 340 × 440 Ancienne administration française
Couronne écriture 360 × 460
Couronne édition 370 × 470
Roberto 390 × 500 Dessin anatomique
Écu 400 × 520
Coquille 440 × 560 Surface proche du A2
Carré 450 × 560
Cavalier 460 × 620 Format publicitaire en presse
Quart-raisin 250 × 325 Papier à dessin scolaire
Demi-raisin 325 × 500 Dessin
Raisin 500 × 650 Dessin
Double raisin 650 × 1000
Grappe de raisin 4000 × 2600 8 raisins
Jésus 560 × 760 Atlas, sentiers et chemins
Soleil 600 × 800
Colombier affiche 600 × 800
Colombier commercial 630 × 900
Petit Aigle 700 × 940 Cartes et plans
Grand Aigle 750 × 1060 Plans cadastraux
Grand Monde 900 × 1260
Univers 1000 × 1300

Japanese Formats (JIS P 0138)

Format Dimensions (mm)
JB0 1030 × 1456
JB1 728 × 1030
JB2 515 × 728
JB3 364 × 515
JB4 257 × 364
JB5 182 × 257
JB6 128 × 182
JB7 91 × 128
JB8 64 × 91
JB9 45 × 64
JB10 32 × 45
JB11 22 × 32
JB12 16 × 22
Shiroku Ban 4 128 × 182
Shiroku Ban 5 189 × 262
Shiroku Ban 6 127 × 188
Kiku 4 227 × 306
Kiku 5 151 × 227

ID Formats (ISO/CEI 7810)

Format Dimensions (mm) Description
ID-000 15 × 25 Mini SIM
ID-1 54 × 85 Carte bancaire
ID-2 74 × 105
ID-3 88 × 125 Passeport

Usage

Available Paper Formats

The class includes the following standard formats:

  • ISO formats (A0-A10, B0-B10, C0-C10)
  • US formats (Letter, Executive, Government Letter, Quarto, etc.)
  • French AFNOR formats (Cloche, Raisin, Jésus, Grand Aigle, etc.)
  • Japanese JIS formats (JB0-JB12, Shiroku Ban, Kiku)
  • ID formats ISO/CEI 7810 (ID-000, ID-1, ID-2, ID-3)

Usage Examples

Unit Conversion

use Ycdev\PaperSize;

// Get A4 dimensions in pixels (default 300 DPI)
$dimensions = PaperSize::px(PaperSize::A4);
// Result: [2480, 3508]

// Get A4 dimensions in centimeters
$dimensions = PaperSize::cm(PaperSize::A4);
// Result: [21.0, 29.7]

// Get A4 dimensions in inches
$dimensions = PaperSize::in(PaperSize::A4);
// Result: [8.27, 11.69]

Creating a GD Image

use Ycdev\PaperSize;

// Create a GD image with A4 dimensions
$image = PaperSize::gdImage(PaperSize::A4);

Calculating Aspect Ratio

use Ycdev\PaperSize;

// Get the aspect ratio of A4 format
$ratio = PaperSize::ratio(PaperSize::A4);
// Result: 1.4142

Landscape Mode

use Ycdev\PaperSize;

// Convert A4 format to landscape
$landscape = PaperSize::landscape(PaperSize::A4);
// Result: [297, 210]

List All Available Formats

use Ycdev\PaperSize;

// Get all available formats
$formats = PaperSize::allFormats();
// Returns an associative array:
// [
//     'A4' => ['width' => 210, 'height' => 297, 'name' => 'A4'],
//     'FR_RAISIN' => ['width' => 500, 'height' => 650, 'name' => 'Fr raisin'],
//     ...
// ]

// Example: populate a <select>
foreach (PaperSize::allFormats() as $key => $format) {
    echo "<option value=\"$key\">{$format['name']} ({$format['width']}x{$format['height']}mm)</option>";
}

Breaking change : allFormats() retourne désormais un tableau associatif avec les clés width, height et name au lieu d'un tableau indexé [width, height, name].

Detect Format from Pixel Dimensions

use Ycdev\PaperSize;

// Detect paper format from pixel dimensions
$format = PaperSize::format(2480, 3507);
// Result: 'A4'

// Works in landscape too
$format = PaperSize::format(3507, 2480);
// Result: 'A4'

// Returns false if no match
$format = PaperSize::format(1, 1);
// Result: false

Crop a GD Image

use Ycdev\PaperSize;

$image = PaperSize::gdImage(PaperSize::A4);
$cropped = PaperSize::crop($image, PaperSize::A5);

Supported Units

  • px (pixels)
  • mm (millimeters)
  • cm (centimeters)
  • m (meters)
  • in (inches)

Resolution

The default resolution for pixel conversions is 300 DPI. You can modify it when calling the methods:

use Ycdev\PaperSize;

// Convert to pixels with 600 DPI resolution
$dimensions = PaperSize::px(PaperSize::A4, 600);

License

GPL V3

ycdev/paper-size 适用场景与选型建议

ycdev/paper-size 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 05 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 ycdev/paper-size 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2025-05-20