beryllium/rawr
Composer 安装命令:
composer require beryllium/rawr
包简介
Image processing library for RAW/CR2 files, providing a wrapper for exiv2 and exiftool
README 文档
README
Rawr is a PHP wrapper for the exiv and exiftool command-line utilities. It enables Preview Extraction, EXIF Data Examination, and EXIF Data Transfer to other image files.
In short: Rawr makes it easier to work with Canon CR2 (RAW) images from within PHP.
Installation Requirements
- PHP 5.4+ or PHP 7
- A writeable temporary folder for performing operations
- System Binaries
exiv2to list and extract previews.exiftoolto transfer EXIF data between files.
Running the unit test suite requires both exiv2 and exiftool present in your path. Testing EXIF data transfer requires the php-exif extension; these tests will be skipped if the extension is not found.
Adding Rawr To Your Project
Require Rawr with Composer:
composer require beryllium/rawr
Then, in your code, instantiate Rawr:
$rawr = new Beryllium\Rawr\Rawr('path/to/sandbox', 'path/to/exiv2', 'path/to/exiftool');
(You can leave off the exiftool value if you are not interested in transferring Exif data.)
Why Do I Need Rawr?
Faster Thumbnails for RAW Photos
Generating thumbnails from RAW photos in PHP is very slow. It's also clunky to wire up Imagick to get the proper output.
Each RAW photo actually has one or more built-in JPG previews stored alongside the camera's raw sensor data. Extracting this preview is a handy shortcut for avoiding PHP's slowness. Batch thumbnail operations are much faster with this approach.
Rawr can list previews:
$rawr->listPreviews('path/to/IMAGE.CR2')
The preview list is an array containing information about each preview. Typically, there is a full-size preview in addition to one or more smaller thumbnails.
The example output below demonstrates:
- 1: 160x120 JPG
- 2: 668x432 TIFF
- 3: 5184x3456 JPG (the full-sized preview)
array(
array(
'index' => 1,
'type' => 'image/jpeg',
'height' => 120,
'width' => 160,
'size' => 14416,
),
array(
'index' => 2,
'type' => 'image/tiff',
'height' => 432,
'width' => 668,
'size' => 1731456,
),
array(
'index' => 3,
'type' => 'image/jpeg',
'height' => 3456,
'width' => 5184,
'size' => 1869241,
),
);
Rawr can extract individual previews:
// extracts the specified preview to the sandbox location and returns the resulting temporary filename
$previewFile = $rawr->extractPreview('path/to/IMAGE.CR2', 3)
You'll want to move the extracted $previewFile out of the sandbox if you want to preserve it. If you're just using it to generate thumbnails, you can leave it in the sandbox and locate the thumbnails elsewhere (and then unlink the $previewFile when you're done).
Don't forget to transfer Exif data to generated thumbnails!
Preserving EXIF Data
Every image taken with your digital camera has special data embedded in the file. This data records the time, camera settings, and even portrait/landscape settings for that image. With some newer cameras, the data can also include GPS coordinates.
Extracting the preview, or even generating a thumbnail from the extracted preview, can result in the loss of this data. Imagick and PHP do not seem to preserve it properly.
Rawr can transfer the EXIF data from the original CR2 file to a JPG:
// to any jpg file
$rawr->transferExifData('path/to/IMAGE.CR2', 'path/to/new_thumbnail.jpg');
// to the preview image you extracted
$rawr->transferExifData('path/to/IMAGE.CR2', $previewFile);
Keep in mind that transferring Exif data can be slow. Expect it to take one or two seconds per call, depending on server CPU/RAM/Disk speed.
Rawr can extract the EXIF data into a consumable format, allowing you to make decisions based on the data:
// translated format
$translatedData = $rawr->listExifData('path/to/IMAGE.CR2', Rawr::EXIF_TRANSLATED);
// raw format
$data = $rawr->listExifData('path/to/IMAGE.CR2');
The Past and Future of Rawr
I built Rawr as part of a home photography project. I needed to quickly generate thumbnails for 22,000 CR2 files. Doing it by rendering the RAW out to a JPG using ImageMagick could've taken years.
If the project helps you out, great! If you find issues with it, please contribute by either logging an issue or a PR on the project.
In the future, I would like to support a wider variety of RAW formats.
beryllium/rawr 适用场景与选型建议
beryllium/rawr 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 95 次下载、GitHub Stars 达 8, 最近一次更新时间为 2016 年 02 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「exif」 「exiftool」 「photo」 「raw」 「exiv2」 「exiv」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 beryllium/rawr 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 beryllium/rawr 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 beryllium/rawr 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Object-Oriented EXIF parsing
Exiftool driver for PHP
PHP client library for FilePreviews.io
Exiftool driver for PHP
Glance project service for managing user photos
Laravel 5 service provider for FilePreviews.io
统计信息
- 总下载量: 95
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-02-10