All posts

CR2 to JPEG via CLI

Develop Canon RAW with dcraw, then encode JPEG with pnmtojpeg.

Open online converter

Packages to install

You need dcraw to read CR2 and netpbm for the pnmtojpeg encoder.

dcraw
netpbm
apt install
sudo apt-get update
sudo apt-get install -y dcraw netpbm

How to run the command

dcraw -w writes a .ppm next to the RAW using camera white balance. Then pnmtojpeg encodes that PPM as JPEG.

dcraw + pnmtojpeg
dcraw -w photo.cr2
pnmtojpeg photo.ppm > photo.jpeg

Dockerfile example

Build a minimal Ubuntu image with the required packages and run the conversion inside the container.

Dockerfile
FROM ubuntu:24.04

RUN apt-get update && \
    apt-get install -y --no-install-recommends \
        dcraw \
        netpbm && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /work
docker build && docker run
docker build -t cr2-to-jpeg .
docker run --rm -v "$PWD:/work" -w /work cr2-to-jpeg \
  dcraw -w photo.cr2

Example commands

Run these locally after installing the packages, or inside the container from the Dockerfile.

Example 1
dcraw -w photo.cr2
pnmtojpeg photo.ppm > photo.jpeg
Example 2
dcraw -w RAW_001.CR2 && pnmtojpeg RAW_001.ppm > RAW_001.jpg