ImageMagick: Invalid ICC profile after conversion - imagemagick

I wrote an application which trims and resizes a bunch of images via ImageMagick. The images are also converted to grayscale. But when I try to open a converted image in Photoshop CC, the following warning appears:
The embedded ICC profile cannot be used because the ICC profile is
invalid, ignoring the profile.
Plus, the image profile is in grayscale, but I want it to be in RGB. How can I achieve this with ImageMagick? I played around with the different parameters, but none worked for me.
This command is currently in use:
convert ${src} -type grayscale -set colorspace RGB -background white -gravity center -extent ${longest}x${longest} ${dest}
Also, this one didn't work either:
convert.exe ${src} -set colorspace RGB -set profile RGB.icc ${dest}

A simple way to force the output PNG to be RGB is to replace $(dest) in your command with PNG24:$(dest), or use PNG32:$(dest) if your image has transparency). If you do this, then your existing RGB color profile will be OK.
You can also try PNG8:$(dest) which will be OK if you have fewer than 256 gray levels, and will result in a smaller file size.

Related

How to change the depth of an image using imagemagick?

I have tried adding the option -depth 12 to the string
convert transparentPNG.png -resize 500x400 -background white -flatten -depth 12 png_small.jpg
The input file is a transparent png to which I'm adding a background and then changing the depth. But the depth remains the same as 8bits. I verified the same using the -verbose.
I'm not sure what could I be doing wrong here. I'm referring to the site link
The transparent input png file used for my test can be found here
Let me know if you have any questions on the tests i did. Hoping to get some tips.
A JPG can only be 8-bit, so your internal 12-bit image is converted back to 8-bit when you save the result.

Ruby + RMagick + base64 image + RGB conversion from GrayScale doesn't work

I'm uploading base64 encoded image to a RoR application. When I receive the image, it has a rgb color scheme (correct), when I write the image on file to be uploaded with paperclip gem, the image color scheme change from rgb to grayscale.
Here is the code:
source = src.gsub(/^data:image\/(png|jpg|jpeg);base64,/,"")
blob = Base64.decode64(source)
img = Magick::Image.from_blob(blob).first
img.colorspace = Magick::SRGBColorspace
img.add_profile "#{Rails.root.to_s}/lib/color_profiles/RGB.icc"
img.write(url = "#{Rails.root.to_s}/tmp/#{self.id}_logo.png")
image = File.open(url)
the img is correctly a RGB image, if I check the resulted created file:
identify -format "%[colorspace]" #{url}
the color scheme is Gray.
Additional info:
The uploaded image is all black with white text, if I upload same image with red background, the final image is correctly an RGB image.
There seems to be a bug in ImageMagick 6.9.9.27 and 7.0.7.15 when reporting the conversion of a grayscale image to RGB PNG. Identify -verbose is reporting grayscale but the string format %[colorspace] is properly reporting sRGB as are the PNG tags. I have reported this bug. For example:
convert logo: -colorspace gray logo.jpg
convert logo.jpg PNG24:logo.png
convert logo.png -format "%[colorspace]" info:
sRGB
identify -verbose logo.png
...
Colorspace: Gray
...
png:IHDR.color-type-orig: 2
png:IHDR.color_type: 2 (Truecolor)
I do not understand. Is your image a color image or a grayscale only image?
IM 6.7.7.10 was during a time that ImageMagick was changing from non-linear gray to linear gray and back again. And also had RGB and sRGB swapped. So you may have a version where gray was linear (darker than non-linear gray) or where RGB and sRGB were swapped. You can convert back to non-linear using one of the following (I do not recall which to use at this time). The other will convert from linear to non-linear. If I assume your input image was grayscale and not color, then try one of these:
convert input -colorspace RGB -colorspace gray result
or
convert input -colorspace sRGB -colorspace gray result
If it is not grayscale, but color only, then leave off the -colorspace gray in these commands.
I would urge you to upgrade if you can. You are well over 200 versions old.
P.S. It is also possible your profile is causing a problem. I don't know what the RGB.icc profile is. Is that an Adobe RGB profile or an sRGB profile.
Can you reproduce your problem using Command Line ImageMagick? If so, post the command line you used. Sorry I do not know Ruby or RMagick.
P.S. 2 Apart from the lighter/darker issue, if you are trying to convert a grayscale image to color, then you will need to specify the output as PNG24:name.png. That is the only way to force a grayscale image to report colorspace=RGB without inserting color pixels.

conversion from xRGB to cmyk imagemagick

I am trying to convert an jpeg image from rgb to cmyk colorspace. Platform is ubuntu 14.04 lts, imagemagick 6.7.7-10
I start with two versions of the image, both rgb. One has an embedded sRGB profile, the other has AdobeRGB. Both are displayer fairly the same in Firefox or Gwenview, quite similar in EOG.
When I convert both images to cmyk using imagemagick:
convert input.jpg -colorspace cmyk test.jpg
then I get two files, that are displayed quite differently. One is considerably darker than the other and both are too dark. It looks like the original profiles have not been used to correctly compute new color values.
One more thing that I observed is, that the resulting image from the xRGB to CMYK conversion still appears to have the AdobeRGB profile embedded, when asking with "identify":
>$ identify -verbose test.jpg | grep -A 5 rofile
Profiles:
Profile-exif: 36738 bytes
Profile-icc: 560 bytes
Description: Adobe RGB (1998)
Manufacturer: Adobe RGB (1998)
Model: Adobe RGB (1998)
Copyright: Copyright 2000 Adobe Systems Incorporated
My understanding is, that a CMYK colorspace cannoth use a RGB profile.
Question: What's wrong in my understanding/usage of ImageMagick or Colorspaces/profiles?
To change both the color model and the ICC profile, I found it necessary to use both -profile and -colorspace. Like this:
convert image.jpg -colorspace CMYK -profile USWebCoatedSWOP.icc image_CMYK_cspace_profile.jpg
Many viewers will not display CMYK JPG correctly unless there is a CMYK profile. If you have an RGB image with a profile, then use profiles to convert rather than -colorspace. In ImageMagick do the following:
convert rgb.jpg -profile path/to/USWebCoatedSwop.icc cmyk.jpg
If the RGB has no profile, then you want to add the rgb profile before the CMYK profile
convert rgb.jpg -profile path/to/sRGB.icc -profile path/to/USWebCoatedSwop.icc cmyk.jpg
Also 6.7.7.10 is rather old and was a release during which many colorspace changes were occurring in ImageMagick. So I strong urge you to upgrade. At the time I write this, it is at 6.9.9.40 and 7.0.7.38.
I think you are confusing colorspaces with profiles. If you just change the colorspace, with -colorspace cmyk, you will only change the colorspace and not the profile, so your existing profile will remain embedded, as you have seen.
I think you need
convert input.jpg -profile cmyk.icm result.jpg
There is an excellent discussion, by Anthony Thyssen, here.

Apply and remove color profile with image magick

I have Tiff images with embedded specific ICC profiles.
I want to convert these by means of imagemagick to JPG-Files.
The JPG-Files should use colorspace sRGB (which is the default) and no embedded profile. In other words I want to apply the profile to the image and want to save it without profile.
When I use a simple convert command like this
convert source.tif target.jpg
the ICC-Profile is preserved in the JPG file. You can remove it with a command like this
convert source.tif +profile "*" target.jpg
But that does not seem to apply the profile.
A -colorspace RGB (or -colorspace sRGB?) should do the trick. But any combination I have tried so far does not work.
Is there a color management guru out there who can give me hint?
`
Some iterations later I come up with this
convert source.tif -profile MY_PROFILE_PATH/sRGB.icc +profile * target.jpg
I used the ICC profile from http://www.color.org/profiles/srgb_appearance.xalter

imagemagick convert CMYK pdf to RGB jpeg or PNG and preseerve colors

I have a cmyk pdf that I am trying to convert to a RGB jpeg or png file but have the colors stay pretty close to what the CMYK version is (compared to how photoshop does it)
I am trying the following command but the colors change drastically from a red color to almost bright neon red and so on.
Here is the command
convert cmykpdf.pdf +profile icc -profile AdobeRGB1998.icc -colorspace sRGB jpegtesting.jpg
Any ideas? or thoughts on how to do this. I tried saving it as a PNG also and same issue occurs and have tried changing sRGB to just RGB
NOTE: It doesnt necessarily need to be RGB jpeg it can even be CMYK jpeg but i just need it to be displayed in the browser correctly and I know safari does not display cmyk jpegs correctly
My goal is to just display a img in the browser that shows the correct color and correct resolution nothing pixilated
The solution is fairly easy, there's nothing voodoo or special about Photoshop's CMYK to RGB nowadays. Imagemagick uses LCMS color engine, which does its job just fine.
But first you'll need to edit delegates.xml file inside IM's directory. Find the line with delegate decode="ps:cmyk" and insert -dUseCIEColor=false near the end, so it looks like that:
<delegate decode="ps:cmyk" restrain="True" command=""#PSDelegate#" -q -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dEPSCrop -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pamcmyk32" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" -dUseCIEColor=false "-f%s" "-f%s""/>
It's necessary because otherwise Ghostscript (before returning pam image to ImageMagick) will perform CMYK to CMYK convertion (assuming DeviceCMYK to be CIEbased CMYK), and you probably don't want that, as colors will shift considerably.
Then try this command:
convert -density 144 cmyk.pdf -profile USWebCoatedSWOP.icc -resample 72 -profile "sRGB Color Space Profile.icm" -quality 100 out.jpg
Here we take cmyk.pdf (rather, temporary pam image that GS returns to IM), assign CMYK profile (just as you do in Photoshop, when you open a file or do it explicitly - therefore choose profile that describes you input CMYK best), convert it to sRGB profile (because I don't think you want AdobeRGB as color space of images for Internet) and save to jpeg. Reduce quality parameter as needed.
One more trick here is additional manual anti-aliasing -- note intermediate resolution of 144 dpi and final 72 dpi. Because I don't think that Ghostscript's anti-aliasing with -dGraphicsAlphaBits=4 is en par with Photoshop's anti-aliasing.
The result of this command looks exactly the same as converted in Photoshop.
You could try this:
convert -negate -colorspace RGB srcfile.jpg outputfile.jpg
Let me know if it works!
Based on previous answers, I finally managed to keep natural colors from a CMYK pdf to a RGB png simply using:
convert -colorspace sRGB cmyk.pdf rbg.png

Resources