How to convert any random image to sRGB ?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
laurens_at_hol
Posts: 20
Joined: 2011-11-16T08:53:16-07:00
Authentication code: 8675308

How to convert any random image to sRGB ?

Post by laurens_at_hol »

Hi,

I have a webapplication where any random image can be uploaded. I want to convert every uploaded image to sRGB.
Can someone help me with this?
Can it be done for every image? What are the steps (commandline options)?

Thanks!
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to convert any random image to sRGB ?

Post by Bonzo »

I have never done it but try:

Code: Select all

convert input -colorspace sRGB output
http://www.imagemagick.org/script/comma ... colorspace
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to convert any random image to sRGB ?

Post by anthony »

Sorry NO.

the SRGB colorspace is miss-named in IMv6. It converts from sRGB to linear RGB.
This aspect will be fixed in a later stage of IMv7 development.

To convert a linear RGB image to sRGB you need to do this

Code: Select all

   convert  -size 100x100 gradient: \
          -set colorspace sRGB -colorspace RGB gradient_sRGB.gif

See Gamma Correction and sRGB Colorspace
http://www.imagemagick.org/Usage/color_ ... perception
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
laurens_at_hol
Posts: 20
Joined: 2011-11-16T08:53:16-07:00
Authentication code: 8675308

Re: How to convert any random image to sRGB ?

Post by laurens_at_hol »

Thanks for your answers.
You are both suggesting to use the -colorspace option, but how about the -profile option then?
Don't I need to use the -profile option in combination with all kinds of profile files (like .icc), as is described in the documentation here: http://www.imagemagick.org/Usage/formats/#color_profile

I'm not quite sure what to do.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to convert any random image to sRGB ?

Post by anthony »

Profile is the better solution, if you can assign the original image a profile. Two profile options will convert the image, as documented in the link provided. Just remember that generally (but not always) any image read is should be assumed to be sRGB already.

The exceptions to this are mathematical or data images, greyscale masks (alpha channels are automatically thought of as linear), and image maps (for position or lighting effects). This makes reading, processing and writing images 'correctly' in IM (or any other image processor) tricky, as each image really needs to have that information specified.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply