15

I am generating thumbnails and medium sized images from large photos. These smaller photos are for display in an online gallery. Many of the photographers are submitting JPEG images using Adobe RGB. I have been asked if the thumbnail and medium size images can use sRGB as the images as is appear "flat" in some browsers.

I'm currently using ImageMagick to create the smaller versions. It has a -colorspace option, but that doesn't seem to do what I want.

Is there any other way to do this? Also, do you think this is worthwhile?

Dave
  • 13,518
  • 7
  • 42
  • 51

4 Answers4

13

You can use the ImageMagic -profile option:

convert image.jpg -profile <adobe.icc> -profile <sRGB.icc> new_image.jpg

See here for more details: http://www.imagemagick.org/Usage/formats/#color_profile.

HaBaLeS
  • 1,809
  • 3
  • 16
  • 26
  • 1
    This command attaches the icc profile file (in this case sRGB), but the problem with image viewer tools it that they don't update the information. Basically one image has more than one profiles attached. Some are simple xml files that records everything a user does in photoshop, records its color profile and things like that. If you attach the binary file sRGB.icc it actually adds the profile, but imagemagick or even photoshop (may be there is menu to update information) does not update other profile files (basically xml), so the image viewer anyway shows previous profile. – Pramod Mar 06 '12 at 06:53
  • 2
    To achieve the best output I declare both: input and output profiles `convert image.jpg -profile -profile new_image.jpg` when I convert the JPG images from my Canon T3i taken with Adobe RGB colorspace. – Rafael Xavier Sep 09 '13 at 17:19
  • 1
    @RafaelXavier where do you get sRGB.icc and adobe.icc from? If I extract profile from original photo it will be adobe.icc. Where does sRGB.icc come from? – Sahil Nov 24 '16 at 16:13
  • @Sahil good question, I don't remember where I got it from by now. Although, it was easy to find them in google sRGB http://www.color.org/srgbprofiles.xalter#v4pref and Adobe https://www.adobe.com/support/downloads/detail.jsp?ftpID=3680 – Rafael Xavier Nov 24 '16 at 16:42
  • 1
    Just to be clear, the main answer here is wrong. You really should following Rafael Xavier's answer her posted above on September 9, 2013:https://stackoverflow.com/questions/817727/converting-jpeg-colorspace-adobe-rgb-to-srgb-on-linux#comment27556053_817817 – bhouston Jun 19 '18 at 17:33
  • 3
    For me, I only needed to do `convert image.jpg -profile new_image.jpg`, as the existing profile is embedded in the file. If I include the Adobe RGB profile first, ImageMagick will convert twice (if I read the docs correctly). – Henrik Mar 30 '20 at 06:14
9

Have you tried using Little CMS? This command will convert an image with a special color profile (i.e. Adobe RGB 1998) to one with no color profile but the same effective colors:

jpgicc -q100 input.jpg output.jpg

I'm setting JPEG quality to 100 here.

Johan
  • 3,667
  • 6
  • 20
  • 25
Kris Wallsmith
  • 8,945
  • 1
  • 37
  • 25
3

The following thread in the ImageMagick forum discusses exactly this in some detail: http://www.imagemagick.org/discourse-server/viewtopic.php?f=1&t=16464

I now use this bash script to convert any picture (including CMYK) to sRGB: http://alma.ch/scripts/any2srgb

It requires icc profiles for images which don't have embedded profiles. These can be found easily on the web. For example on Adobe's site: http://www.adobe.com/cfusion/search/index.cfm?term=icc+profile&siteSection=support%3Adownloads

Here is a summary (untested) of what the full script does (without it's resize and other options). It requires profiles and ImageMagick. On Debian-based systems: apt-get install icc-profiles imagemagick.

#!/bin/bash

srgb=sRGB.icm
cmyk=ISOwebcoated.icc

# extract possible color profile
profile="${f/%.*/.icc}"
convert "$f" "icc:$profile" 2>/dev/null

if cmp -s "$profile" "$srgb" ; then
    # embedded profile is already srgb. Nothing to do
    exit
fi

if [ -s "$profile" ]; then
    # we have an embedded profile, so ImageMagick will use that anyway
    convert "$f" -profile "$srgb" +profile '*' "$outfile"
else
    # no embedded profile in source
    if identify -format "%r" "$f" | grep -q CMYK; then
        # CMYK file without embedded profile
        convert "$f" -profile "$cmyk" -profile "$srgb" "$outfile"
    fi
fi
mivk
  • 13,452
  • 5
  • 76
  • 69
  • 1
    @Boris : it's already in the 4th paragraph: `apt-get install icc-profiles`. Well, at least for Debian-based distributions. – mivk Dec 05 '21 at 15:38
0

Re-exporting the image using Krita seems to work well enough for me:

 krita my_img.jpg --export --export-filename my_img_in_srgb.jpg

Krita is an open source Photoshop/Paint, with a(n extremely limited) command line interface. Install it with

sudo apt install krita
Boris Verkhovskiy
  • 14,854
  • 11
  • 100
  • 103