Converting images to sRGB
Converting images to sRGB
Hi all
I'm trying to convert a really big batch of jpgs/pngs to sRGB.
I read a lot about it, but I keep having the same issues,
I tried
<?php
header("Content-type: image/jpeg");
$IMagick = new IMagick('D:\img\test.jpg');
$IMagick->setImageColorSpace(Imagick::COLORSPACE_SRGB);
echo $IMagick;
?>
But didn't work, the final image isn't sRGB, somewhere I read about that COLORSPACE_SRGB works backwards, I tried but the image looks super wash, with light colors.
PHP: 5.5.11
XAMP: 1.8.3
Compiler: MSVC11
ImageMagick: 6.7.7-5.q16
imagick.dll php 5.5.xx
I'm trying to convert a really big batch of jpgs/pngs to sRGB.
I read a lot about it, but I keep having the same issues,
I tried
<?php
header("Content-type: image/jpeg");
$IMagick = new IMagick('D:\img\test.jpg');
$IMagick->setImageColorSpace(Imagick::COLORSPACE_SRGB);
echo $IMagick;
?>
But didn't work, the final image isn't sRGB, somewhere I read about that COLORSPACE_SRGB works backwards, I tried but the image looks super wash, with light colors.
PHP: 5.5.11
XAMP: 1.8.3
Compiler: MSVC11
ImageMagick: 6.7.7-5.q16
imagick.dll php 5.5.xx
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting images to sRGB
What colorspace are the input images? Your version of IM was right at the time colorspace was being worked on and reversed. It is not clear if that was working correctly or had bugs at that time. You would be better off using profiles to change colorspaces.
Re: Converting images to sRGB
Thank you Fred for your quick answer.
The input files are RGB.
I had to process about 40k/60k images using Photoshop actions. About 10 days ago I started working in a PHP that saves me about 80% (or more) of the time required, and reducing the risk of any error to 0.
The final issue that I had was that all the images that GD/php delivered were RGB, they have to be sRGB. So start working with Imagick.
If you can, give me a clue to start using profiles.
Thank you again, and sorry for my rusty english.
The input files are RGB.
I had to process about 40k/60k images using Photoshop actions. About 10 days ago I started working in a PHP that saves me about 80% (or more) of the time required, and reducing the risk of any error to 0.
The final issue that I had was that all the images that GD/php delivered were RGB, they have to be sRGB. So start working with Imagick.
If you can, give me a clue to start using profiles.
Thank you again, and sorry for my rusty english.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting images to sRGB
Can you upload one of your RGB images to some free hosting service such a dropbox.com (public folder) and put a link here. I want to be sure it is really RGB and sRGB, since in your version and older they were swapped. So if IM reported RGB in your version, then it was probably already sRGB, unless it has an imbedded profile.
Re: Converting images to sRGB
This is what I have -> https://www.dropbox.com/s/u672cpgo1sxhupv/have.jpg
& this is what I need to output ->https://www.dropbox.com/s/oxhfszd50vxl6h8/want.jpg
Thank you, I have my plan B, using an action in Photoshop, but I prefer to solve everything in my php/gd/imagick
& this is what I need to output ->https://www.dropbox.com/s/oxhfszd50vxl6h8/want.jpg
Thank you, I have my plan B, using an action in Photoshop, but I prefer to solve everything in my php/gd/imagick
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting images to sRGB
Both your images are sRGB. The first has no profile. The second has some HP sRGB profile (sRGB IEC61966-2.1). Furthermore, PS has dot gains that IM cannot reproduce. So I am not 100% sure you will be able to get this perfectly reproduced. I am off to lunch, but when I get back, I will see if I can find that profile and do some tests. Did you load the first into PS and save with that profile? Where did the first image come from? Can you open your Color Settings window showing all the options and make a screen snap of what you have selected there and put a link here?
Re: Converting images to sRGB
Thank you much for your time.
The original process was: I had a Master psd, and I have to add the new number (as you can see in this images #9) and then I have to apply an action in photoshop, this action will resize, transform, hide layers, change layer and save and renaming each image. As result I will have about 500 different files, and I had to do it again from #1 to #65 or whatever, I took a life.
The new process is: I had the same master, I applied the action but without adding the number, I import these 500 images to my php, And they will be resized, transformed, getting the right number, using GD.
At this point everything was great. I was saving about 70%/80% of time and there is no risk of error.
But the php/gd output is different to the original process, as you can see in the previous samples, the second one less brighter. I try it investigate what is the cause of this, and click right and looking the images details, the second ones shows the "Color Representation sRGB" and "Resolution Unit 2", the first ones don't have any value.
But when I import the first one into the PS, and convert to the sRGB IEC61966-2.1 color profile, both images looks like the same, with same properties details.
GD doesn't work with color profiles, so I started trying solve it using IM.
Color Setting from PS --> https://www.dropbox.com/s/0nc3f1zkhr3wq ... ngs_PS.jpg
Just to be clear. I use the second one as an input to get the first one, and my goal is get the first one the more similar possible to the second one.
Thank you for you time.
The original process was: I had a Master psd, and I have to add the new number (as you can see in this images #9) and then I have to apply an action in photoshop, this action will resize, transform, hide layers, change layer and save and renaming each image. As result I will have about 500 different files, and I had to do it again from #1 to #65 or whatever, I took a life.
The new process is: I had the same master, I applied the action but without adding the number, I import these 500 images to my php, And they will be resized, transformed, getting the right number, using GD.
At this point everything was great. I was saving about 70%/80% of time and there is no risk of error.
But the php/gd output is different to the original process, as you can see in the previous samples, the second one less brighter. I try it investigate what is the cause of this, and click right and looking the images details, the second ones shows the "Color Representation sRGB" and "Resolution Unit 2", the first ones don't have any value.
But when I import the first one into the PS, and convert to the sRGB IEC61966-2.1 color profile, both images looks like the same, with same properties details.
GD doesn't work with color profiles, so I started trying solve it using IM.
Color Setting from PS --> https://www.dropbox.com/s/0nc3f1zkhr3wq ... ngs_PS.jpg
Just to be clear. I use the second one as an input to get the first one, and my goal is get the first one the more similar possible to the second one.
Thank you for you time.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting images to sRGB
I can get closer by attaching the proper sRGB.icc profile. Note there are differences in sRGB.icc profiles (different versions, etc). I got the latter two from http://www.color.org/srgbprofiles.xalter. The first and second seem to be the same. I had the first around and probably came with IM. The latter is different. The first two are perceptual color and the last is not.
I think the remaining differences are due to the PS dot gain, which I cannot seem to turn off in PS and IM does not support.
You can see examples of using profiles in Imagick in the examples at http://us3.php.net/manual/en/imagick.se ... rspace.php
Code: Select all
convert have.jpg -profile /Users/fred/images/Profiles/sRGB.icc have_srgb.jpg
Code: Select all
convert have.jpg -profile /Users/fred/images/Profiles/sRGB_IEC61966-2-1_black_scaled.icc have_srgb_bs.jpg
Code: Select all
convert have.jpg -profile /Users/fred/images/Profiles/sRGB_IEC61966-2-1_no_black_scaling.icc have_srgb_nobs.jpg
I think the remaining differences are due to the PS dot gain, which I cannot seem to turn off in PS and IM does not support.
You can see examples of using profiles in Imagick in the examples at http://us3.php.net/manual/en/imagick.se ... rspace.php
Re: Converting images to sRGB
Thank you Fred, you really help me.
The second looks really close.
Two little things,
could you put down the images I don't have the rights to publish them. =(
and, what should I do to maintain the 96dpi in the output?
Again, thank you so mush, really help me.
The second looks really close.
Two little things,
could you put down the images I don't have the rights to publish them. =(
and, what should I do to maintain the 96dpi in the output?
Again, thank you so mush, really help me.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting images to sRGB
Goodneokid wrote:Thank you Fred, you really help me.
The second looks really close.
OKneokid wrote:Two little things,
could you put down the images I don't have the rights to publish them. =(
Just add -density 96 -units pixelsperinch just before the output. You can also set the -quality XX to control the amount of compression if you want. See http://www.imagemagick.org/script/comma ... hp#qualityneokid wrote:and, what should I do to maintain the 96dpi in the output?
Re: Converting images to sRGB
I solved the issues, thanks to you, now I'm converting them using the profile directly from my php. A++++
I had one final problem, strange one.
I had few PNGs, I processed them the same way that the jpegs, but I see the correct colors in FF and PS, and badly in Chrome. (the same differences that I had before with the profile colors in jpeg).
Could you give me some clue to start investigating and solving.
I have ---> https://www.dropbox.com/s/mqi8ma5hne880sc/final.png
I should have ----> https://www.dropbox.com/s/0axi4w0dzxl47 ... D_PS20.png
Thank you again, have a great weekend, if someday you plan to visit Buenos Aires, the drinks are on me.
I had one final problem, strange one.
I had few PNGs, I processed them the same way that the jpegs, but I see the correct colors in FF and PS, and badly in Chrome. (the same differences that I had before with the profile colors in jpeg).
Could you give me some clue to start investigating and solving.
I have ---> https://www.dropbox.com/s/mqi8ma5hne880sc/final.png
I should have ----> https://www.dropbox.com/s/0axi4w0dzxl47 ... D_PS20.png
Thank you again, have a great weekend, if someday you plan to visit Buenos Aires, the drinks are on me.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting images to sRGB
The two images are virtually identical.
compare -metric rmse final.png want_EN_HD_PS20.png null:
540.759 (0.00825146)
That is 0.8% difference. Only the red channel is a tad different. You can compare the result from using identify -verbose image.png.
mean: 100.771 (0.39518)
vs
mean: 100.787 (0.395243)
The only difference is that want_EN_HD_PS20.png has a fully opaque alpha channel and final.png has no alpha channel. Just remove the alpha channel with -alpha off before writing the output. It won't hurt if there is no alpha channel. If the input has an alpha channel that is not fully opaque, it will get removed. So you need to either test for that or decide if you don't expect any transparent alpha channels.
Or just add an opaque alpha channel with -alpha opaque, if that is better for you, though it means the image file will be larger.
It is possible that different browsers handle the opaque alpha channel differently. I have seen differences in how various browsers render image.
Can you provide the input image and the commands you use for the two results or how you got two different results?
If any of your input jpgs are CMYK and have no profile, then you must use two profiles to convert to sRGB PNG since PNG does not support CMYK.
P.S. The main problem is that neither of the images you provided has an icc profile. Thus different browser may render them differently. So either you uploaded the wrong files or your addition of profiles did not work. Did you provide the full path where your profiles reside and do you have the sRGB.icc profile file?
For your final.png, the verbose info shows
When I do
the verbose info shows
Note at the end of the latter you will see Profile-icc: 6876 bytes And the properties list
icc sRGB built-in
icc:description: sRGB built-in
icc:manufacturer: (lcms internal)
icc:model: sRGB built-in
compare -metric rmse final.png want_EN_HD_PS20.png null:
540.759 (0.00825146)
That is 0.8% difference. Only the red channel is a tad different. You can compare the result from using identify -verbose image.png.
mean: 100.771 (0.39518)
vs
mean: 100.787 (0.395243)
The only difference is that want_EN_HD_PS20.png has a fully opaque alpha channel and final.png has no alpha channel. Just remove the alpha channel with -alpha off before writing the output. It won't hurt if there is no alpha channel. If the input has an alpha channel that is not fully opaque, it will get removed. So you need to either test for that or decide if you don't expect any transparent alpha channels.
Or just add an opaque alpha channel with -alpha opaque, if that is better for you, though it means the image file will be larger.
It is possible that different browsers handle the opaque alpha channel differently. I have seen differences in how various browsers render image.
Can you provide the input image and the commands you use for the two results or how you got two different results?
If any of your input jpgs are CMYK and have no profile, then you must use two profiles to convert to sRGB PNG since PNG does not support CMYK.
P.S. The main problem is that neither of the images you provided has an icc profile. Thus different browser may render them differently. So either you uploaded the wrong files or your addition of profiles did not work. Did you provide the full path where your profiles reside and do you have the sRGB.icc profile file?
For your final.png, the verbose info shows
Code: Select all
Properties:
date:create: 2014-05-03T12:15:06-07:00
date:modify: 2014-05-03T12:15:06-07:00
png:bKGD: chunk was found (see Background color, above)
png:cHRM: chunk was found (see Chromaticity, above)
png:gAMA: gamma=0.45455 (See Gamma, above)
png:IHDR.bit-depth-orig: 8
png:IHDR.bit_depth: 8
png:IHDR.color-type-orig: 2
png:IHDR.color_type: 2 (Truecolor)
png:IHDR.interlace_method: 0 (Not interlaced)
png:IHDR.width,height: 600, 882
png:pHYs: x_res=72, y_res=72, units=0
png:sRGB: intent=0 (Perceptual Intent)
png:text: 2 tEXt/zTXt/iTXt chunks were found
signature: 3f92ebd6c1e247df9ca64c0c396998c238359a41be36f51f5890cc8c183eeebd
Artifacts:
Code: Select all
convert final.png -profile /Users/fred/images/Profiles/sRGB.icc final2.png
Code: Select all
Properties:
date:create: 2014-05-03T12:39:16-07:00
date:modify: 2014-05-03T12:39:16-07:00
icc:copyright: sRGB built-in
icc:description: sRGB built-in
icc:manufacturer: (lcms internal)
icc:model: sRGB built-in
png:bKGD: chunk was found (see Background color, above)
png:cHRM: chunk was found (see Chromaticity, above)
png:iCCP: chunk was found
png:IHDR.bit-depth-orig: 8
png:IHDR.bit_depth: 8
png:IHDR.color-type-orig: 2
png:IHDR.color_type: 2 (Truecolor)
png:IHDR.interlace_method: 0 (Not interlaced)
png:IHDR.width,height: 600, 882
png:pHYs: x_res=72, y_res=72, units=0
png:text: 6 tEXt/zTXt/iTXt chunks were found
signature: 3f92ebd6c1e247df9ca64c0c396998c238359a41be36f51f5890cc8c183eeebd
Profiles:
Profile-icc: 6876 bytes
Artifacts:
icc sRGB built-in
icc:description: sRGB built-in
icc:manufacturer: (lcms internal)
icc:model: sRGB built-in
Re: Converting images to sRGB
Thank you, It works great. I was working around, changing php/GD for imagick, and it works slower but great. (all the issues in the JPGs are gone, and the PNGs are quite good.)
The only thing that I got stucked was trying to add a profile to a PNG, I tried everything.
it worked for the JPGs.
Tried to clean using "strip" and +profile, and then adding it, but not luck.
The only thing that I got stucked was trying to add a profile to a PNG, I tried everything.
Code: Select all
convert d:\xampp2\htdocs\posters\PS20.png -profile d:\iccs\sRGB_IEC61966-2-1_black_scaled.icc d:\xampp2\htdocs\posters\PS20wicc.png
Code: Select all
Properties:
date:create: 2014-05-05T18:58:54-03:00
date:modify: 2014-05-05T18:36:42-03:00
png:bKGD : chunk was found (see Background color, above)
png:cHRM : chunk was found (see Chromaticity, above)
png:gAMA : gamma=0.45454544 (See Gamma, above)
png:IHDR.bit_depth : 8
png:IHDR.color_type : 6
png:IHDR.interlace_method: 0
png:IHDR.width,height : 600, 882
png:pHYs : x_res=3780, y_res=3780, units=1
png:sRGB : intent=0 (See Rendering intent)
png:text : 2 tEXt/zTXt/iTXt chunks were found
signature: 33bdca521740b99af2e97f2e84a7719110ad94423688ec8e31f7c01131f269e4
Artifacts:
filename: d:\xampp2\htdocs\posters\PS20wicc.png
verbose: true
Tainted: False
Filesize: 268KB
Number pixels: 529K
Pixels per second: 14.7MB
User time: 0.031u
Elapsed time: 0:01.035
Version: ImageMagick 6.7.7-4 2012-05-29 Q16 http://www.imagemagick.org
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Converting images to sRGB
It is likely a bug or limitation of your old version of IM (over 100 versions old). I would suggest you upgrade.
Re: Converting images to sRGB
I want it, but news version aren't supported by xampp 1.8.3.