Converting Canon CR2 Images to JPEG and Image Manipulation Techniques
Every camera has their own format of file, for me as a Canon user I get the Canon CR2 files to manage, a raw image format from Canon cameras that offers a lot of detail and flexibility but isn’t as readily usable as standard formats like JPEG. In this blog post, we’ll look at how to convert CR2 files to JPEG and explore other image manipulation techniques using command-line tools.
Converting CR2 to JPEG
I keep this deliberately small: ImageMagick 7 plus LibRaw command-line tools. On macOS with Homebrew:
brew install imagemagick libraw
First I check whether this ImageMagick build already has a RAW delegate:
magick identify input.CR2
magick input.CR2 -quality 90 output.jpg
If that works, it is the shortest path. Otherwise LibRaw’s dcraw_emu gives me a two-step fallback without a photo-management application:
dcraw_emu -T -w -o 1 -O output.tiff input.CR2
magick output.tiff -quality 90 output.jpg
For a directory I preview the files, then run the same conversion per image. ImageMagick 7 uses magick; convert is the older ImageMagick 6 form. ImageMagick 7 porting guide and LibRaw utilities
Image Resizing
imagemagick isn’t just for format conversions; it also allows us to perform various image manipulations like resizing.
Resizing to a Specific Width
If you want to resize an image to a specific width while keeping the aspect ratio, use the following command:
magick image1.gif -resize 300x image2.gif
Resizing to a Specific Height
Similarly, for resizing to a specific height while keeping the aspect ratio:
magick image1.gif -resize x200 image2.gif
Resizing Within a Width and Height Container
If you need to fit an image within a specific width and height while keeping the aspect ratio, use:
magick image1.gif -resize 300x200 image2.gif
Resizing by Percentage
To resize an image by a certain percentage, use:
magick image1.gif -resize 50% image2.gif
Handling Animated GIFs
Animated GIFs require an extra step before resizing: they first need to be coalesced. Coalescing an animated GIF undoes all optimizations that may be present in the original GIF, expanding all frames to full size:
magick image_animation_1.gif -coalesce -resize x200 -layers Optimize image2.gif
Reducing Colors
To reduce the color depth of an image, imagemagick provides a simple command:
magick img1.png +dither -colors 256 img2.png
You can replace 256 with any number depending on how many colors you want in the output image.
Image Cropping
For cropping an image to a certain size with a specific starting point, use:
magick convert-crop-img1.jpg -crop 240x160+100+50 +repage convert-crop-img2.jpg
Image Compression
Image compression is a method to reduce the image file size without degrading the quality of the image below an acceptable level. For this purpose, we’ll use jpegoptim:
jpegoptim --size=500k /home/net2_admin/lion.jpeg
To compress all JPEGs in a directory by a percentage, use:
for i in *.jpg; do jpegoptim -m70 "$i"; done
Add -n for a dry run; the shown command performs the optimization.
Photography isn’t just about capturing; it’s also about proper editing and presentation. By knowing these image manipulation techniques, you can ensure your photographs are displayed exactly as you want them to be, regardless of the format they were captured in.
Buy Me a Coffee