Download the PHP package ronanlenouvel/raw-preview-extractor without Composer

On this page you can find all versions of the php package ronanlenouvel/raw-preview-extractor. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package raw-preview-extractor

Raw Preview Extractor

Extract the JPEG preview embedded in camera RAW files — pure PHP, no external binaries.

CI

Status: feature-complete and validated against real camera files (see Tested cameras). The public API is settled, but a released version is a semver commitment, and more cameras are worth testing first.

Why

Displaying a thumbnail for a RAW file normally means decoding it, which requires libraw or Imagick — unavailable on shared hosting without root access.

Almost every modern camera already embeds a full JPEG preview inside its RAW files. This library locates and extracts that JPEG by reading the container structure. No demosaicing, no sensor data, no dependencies: just byte reading.

Supported formats

Format Container Detected by
CR2 (Canon) TIFF 6.0 CR signature
CR3 (Canon) ISO-BMFF ftyp + crx brand
NEF (Nikon) TIFF 6.0 Make tag
ARW (Sony) TIFF 6.0 Make tag
DNG (Adobe) TIFF 6.0 DNGVersion tag

Detection reads the file's binary signature, never its extension: a .cr2 renamed to .jpg is still detected as a CR2, and a .cr2 that isn't one is rejected.

RAF (Fuji) and ORF (Olympus) are planned for v2.

Requirements

PHP >= 8.2. That's it — the require section depends on nothing else.

The optional Symfony bundle supports 6.4 (LTS), 7.x and 8.x. Composer picks whichever matches your application; the library itself never depends on Symfony.

Installation

Usage

Orientation

A preview is stored exactly as the sensor captured it: a shot taken in portrait comes out lying on its side. The camera records the rotation rather than applying it.

This library does not rotate the image — that would need GD, the very dependency it exists to avoid. It tells you what the file says:

In a browser, fixing it costs nothing:

Server-side, if you do have GD — note it rotates counter-clockwise:

Check support before extracting:

Processing a directory — the whole library in one loop:

Extraction is O(1) in file size: a 30 MB RAW takes the same ~2 ms as a 7 MB one, because the file is never loaded — only its container structure is read, then the JPEG block is seeked to directly.

Metadata

Alongside the preview, the extractor reads the shooting settings from the RAW's EXIF — what a photographer wants next to the image: when it was taken, and how.

Every field is nullable, and so is $preview->metadata itself: a tag may be absent, an old body says less than a recent one, and a partial read is never a failure. RawMetadata::isEmpty() tells a caller nothing usable was found, in one call:

Values are exposed exactly as the file encodes them — no rounding, no locale: the shutter speed keeps its fraction ("1/250" reads better than 0.004), the aperture stays a plain number. Metadata is read from the same container walk as the preview, so it costs nothing extra.

Coverage follows the TIFF-based formats (CR2, NEF, ARW, DNG), which carry EXIF in a standard IFD. For CR3 (ISO-BMFF) the preview is returned but metadata is currently null.

Exceptions

All of them implement RawPreviewExtractorException:

Exception Meaning
UnsupportedFormatException not a supported RAW file
PreviewNotFoundException valid file, but no embedded JPEG preview
CorruptedFileException unreadable or structurally invalid file

Symfony integration (optional)

The package ships a thin, optional bundle. The core library itself knows nothing about Symfony and works in any PHP project.

RawPreviewExtractorInterface then becomes autowirable.

Tested cameras

Verified against real files from raw.pixls.us (CC0):

All five formats are verified against real camera files:

Camera Year Format File Preview extracted
Canon EOS 5D 2005 CR2 13 MB 2496×1664 — 1656 KB
Canon EOS 5D Mark II 2008 CR2 27 MB 5616×3744 — 1980 KB
Canon 5D Mark II sRAW1 2008 CR2 15 MB 5616×3744 — 1973 KB
Canon EOS 5D Mark IV 2016 CR2 62 MB 6720×4480 — 2047 KB
Canon EOS R 2018 CR3 30 MB 1620×1080 — 228 KB
Canon EOS RP 2019 CR3 7 MB 1620×1080 — 328 KB
Nikon D750 2014 NEF 25 MB 6016×4016 — 952 KB
Sony α7 (ILCE-7) 2013 ARW 24 MB 1616×1080 — 460 KB
Apple iPhone 12 Pro 2020 DNG 29 MB 4032×3024 — 5239 KB

Four generations of the same Canon 5D line — 2005 to 2016, 12 to 30 megapixels — are covered deliberately: RAW layout drifts between generations, and that drift is where format parsers break.

Wider audit

Beyond the table above, the library is audited against the raw.pixls.us catalogue — 400+ camera models, CC0 files:

Each file is downloaded, extracted, verified with imagecreatefromstring(), then deleted. Latest run — 72 models across the four brands in scope:

Brand Passed Notes
Sony 23/23 100 % — A290 (2010) through FX30
Nikon 20/22 90.9 %
Apple 5/6 83.3 %
Canon 16/21 76.2 % — every EOS body passed

Every failure was verified by hand, and every one is correct: those files contain no JPEG preview at all (zero FFD8 bytes in the entire file). A Nikon D1H from 2001 carries an uncompressed 160×120 RGB thumbnail; CHDK-generated compact DNGs do the same; legacy .CRW files predate CR2 and are out of scope. PreviewNotFoundException is the right answer, so the real success rate on files that have a preview is 100 %.

The full list is at the bottom of this page.

Every preview above is checked with imagecreatefromstring() — not just decoded headers, but actually opened. Extraction takes 1–9 ms on files up to 62 MB: the file is never loaded into memory, only the container structure is read before seeking to the JPEG block.

RAW layout varies between camera generations, and CR3 has no public specification. If your camera is not listed, the library may well work — it just has not been verified. You can check in one command: see Trying it on your own RAW files.

Contributing

See CONTRIBUTING.md for conventions, the TDD workflow, and the binary parsing rules. In short:

The suite runs on a clean machine with no RAW file whatsoever: tests build byte sequences in memory. No camera files are committed to this repository — a RAW carries EXIF data (serial number, sometimes GPS), and a committed binary stays in git history forever.

Trying it on your own RAW files

Synthetic tests prove the parsing is correct; they cannot prove your camera lays out its IFDs the way this library expects. To check for yourself:

Extracted previews are written to tests/Fixtures/local/output/open them. A JPEG that decodes is not necessarily the right JPEG: this library once returned a valid 160×120 thumbnail where a 1620×1080 preview was expected, and every test was green.

Neither the RAW files nor the extracted previews are committed. The script itself lives in bin/, excluded from the published archive by .gitattributes.

Free CC0 sample files for most cameras: raw.pixls.us.

License

MIT — see LICENSE.

exiftool and libraw were used as behavioural references only. No code was copied from either project.


Appendix: models verified against real files

Every model below had a real file downloaded, its preview extracted, and the result opened with imagecreatefromstring(). Sources: raw.pixls.us (CC0).

Canon — CR2 & CR3

Nikon — NEF

Sony — ARW

Apple — DNG (including ProRAW)

Known to have no preview

These models throw PreviewNotFoundExceptionand that is the correct answer. Their files contain no JPEG whatsoever, which is verifiable in one command:

Model What the file actually holds
Nikon D1H (2001) uncompressed 160×120 RGB thumbnail
Nikon COOLSCAN V ED film scanner output
Apple iPhone 8 64 sensor tiles, no JPEG
Canon PowerShot SX100 IS, SX510 HS, ELPH 130 IS uncompressed 128×96 thumbnail
Canon PowerShot G7 X, IXY 220F .CRW — pre-CR2, out of scope

Two reasons, neither of them a parser bug. The oldest bodies predate the convention: a D1H from 2001 stores a raw RGB thumbnail because embedding a JPEG preview was not yet standard practice. The compacts never had a RAW mode: their DNGs come from CHDK, an alternative firmware that writes sensor data with a minimal thumbnail.

There is nothing to extract in those files, so throwing is right — returning something would mean fabricating it.

Success rate on files that actually contain a preview: 100 %.


All versions of raw-preview-extractor with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ronanlenouvel/raw-preview-extractor contains the following files

Loading the files please wait ...