Adding Colorspace and ICC profile after Composite

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
twaintwist
Posts: 12
Joined: 2012-05-01T18:36:28-07:00
Authentication code: 13

Adding Colorspace and ICC profile after Composite

Post by twaintwist »

I'm overlaying text on .png images using Composite --- which wipes the metadata. I've found a way to export the metadata from the images and then add back to the image (using exiv2).... but it fails to handle the colorspace and color profile.

I believe the -colorspace depends on the input image having a colorspace to begin with --- how do I add colorspace (e.g. sRGB) to an image file (.png) when the original colorspace was stripped during the composite step? I also need to add the ICC profile... but until I get the colorspace the -profile does not seem to work either.

I'm using ImageMagick-6.8.7-Q16

and the original and resulting images:
https://plus.google.com/photos/10681131 ... 6953751118
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Adding Colorspace and ICC profile after Composite

Post by snibgo »

I can't see your images without signing in. Please put them somewhere like dropbox.com that doesn't require a sign-in.

What is your exact command for overlaying text?

I always use "convert", not "composite". I think convert can do everything that composite can do.

Colorspaces are added with "-profile". See http://www.imagemagick.org/script/comma ... hp#profile
snibgo's IM pages: im.snibgo.com
twaintwist
Posts: 12
Joined: 2012-05-01T18:36:28-07:00
Authentication code: 13

Re: Adding Colorspace and ICC profile after Composite

Post by twaintwist »

Sorry about that --- I thought I made the images public ---- here is a dropbox link https://www.dropbox.com/l/DpMTvW6MDFxFKFMUdDcEab

And I'd like to use Composite because the text length varies and I'd like all the text to fit within a region on the print..... perhaps there is a better way using convert....

Code: Select all

   
       REM ************** Create the text area *********************************************************
	convert AddLabel_Resources\Caption2.png -font "AddLabel_Resources\ARDS1.ttf" -background Transparent -fill "rgb(255,255,255)" -size 506x285  caption:"!FirstLine!" c:\scratchprocess\Caption.png

   REM ************ Place shade behind text to make it readable *************************
	composite -geometry 506x285+32+32 c:\AddLabel_Resources\Caption3.png c:\tempfolder\!image_temp! c:\tempfolder\!image_temp!

   REM ************ compose the text onto the image *************************************
	composite -geometry 506x285+32+32 c:\scratchprocess\Caption-1.png c:\tempfolder\!image_temp! c:\tempfolder\!image_temp!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Adding Colorspace and ICC profile after Composite

Post by snibgo »

I don't understand your problem. Your file "original.png" contains no profile. The pixels are encoded as sRGB, in other words the colorspace is sRGB. (I know this because "identify -verbose original.png" shows red, green and blue channels, and the gamma is 0.454545.) The file Annotated-without-Colorspace is also sRGB with no profile.

Does "original.png" correspond to any of the files in your script?

The first command reads caption2.png, creates a captioned image, and writes these as two images (caption-0.png and caption-1.png). Caption-0.png is never used, and neither is caption2.png.

The second command reads a different file, caption3.png, and writes that over !image_temp!.

The third command writes caption-1.png over !image_temp!.

The three commands could be combined into one, saving multiple reads and writes. For example:

Code: Select all

set FirstLine=This is a test

%IM%convert ^
  -background rgba(0,0,0,0.5) -fill "rgb(255,255,255)" -size 506x285  caption:"!FirstLine!" ^
  original.png ^
  +swap ^
  -composite ^
  out.png
snibgo's IM pages: im.snibgo.com
twaintwist
Posts: 12
Joined: 2012-05-01T18:36:28-07:00
Authentication code: 13

Re: Adding Colorspace and ICC profile after Composite

Post by twaintwist »

Thanks for the reply....

When I view the original file there is sRGB colorspace and an ICC profile ..... see https://www.dropbox.com/l/GsLDUQvqcLLJfr62FURxXe ---- but after compositing the colorspace and ICC profile are missing....

I'm looping through a folder of images --- so the c:\tempfolder\!image_temp! is the original image - and then subsequently is composited via further steps.

For Caption --- I created a boundary/area for the caption ( i.e. caption2.png).... a simple rectangle filled with black). I also created a semi-transparent file (i.e. caption3.png) that is to be placed behind the text so that the white text stands out from the modulated scene.

I'm most likely using the Caption command incorrectly --- but what has worked for me is to compose Caption-1.png (created by 'caption:' ) onto the image area.

Thanks for the 1-liner --- I gave it a quick try but it failed with a '-fill was unexpected at this time.'
twaintwist
Posts: 12
Joined: 2012-05-01T18:36:28-07:00
Authentication code: 13

Re: Adding Colorspace and ICC profile after Composite

Post by twaintwist »

OK --- I re-typed your one-liner and now it works ----- just had to add quotes around "rgba(0,0,0,0.5)".....

But the sRGB and ICC profiles are still stripped with the composite step....
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Adding Colorspace and ICC profile after Composite

Post by snibgo »

These days, software assumes that images are sRGB unless they are labelled otherwise.

Your file Original.png has no indicator of colorspace. Most software will assume it is sRGB.

If you want it to contain an indicator, put "-profile sRGB.icc" in your command, before the output filename.

IM won't put the profile in a PNG file, but will create an sRGB chunk:

Code: Select all

identify -verbose original.png
:
    png:sRGB: intent=0 (Perceptual Intent)
sRGB.icc must exist in your current directory. If you know the x.jpg contains the profile, you can create sRGB.icc:

Code: Select all

convert x.jpg sRGB.icc
snibgo's IM pages: im.snibgo.com
twaintwist
Posts: 12
Joined: 2012-05-01T18:36:28-07:00
Authentication code: 13

Re: Adding Colorspace and ICC profile after Composite

Post by twaintwist »

Thanks for the info....

Here is the initial jpeg https://www.dropbox.com/l/I4SNBsWYcOWQa8WttAZ0va

then card image is run through some Photoshop JS scripts to extract the 'card' image ----- and create the png with the xmp 'comment' field as well as preserving the colorspace and ICC profile.

I can't seem to create the sRGB.icc .... receive error "convert.exe; no color profile is available c:\temp\sRGB.icc'

In Photoshop the ICC is IEC61966-21.icc

When I attempt to run the "-profile IEC61966-21.icc" I receive error " convert.exe; UnableToTransformColorspace 'output.png' @warning/profile.c/LCMSExceptionHandler/446
convert.exe; ColorspaceColorProfileMismatch 'icc' @error/profile.c/ProfileImage/588.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adding Colorspace and ICC profile after Composite

Post by fmw42 »

You may have to download the sRGB.icc profile. It often can be found on your system if you search. You can download the sRGB.icc profile from http://www.color.org/srgbprofiles.xalter. There are various versions there. Put it where you want or find and then put the full path to it with the -profile command.
twaintwist
Posts: 12
Joined: 2012-05-01T18:36:28-07:00
Authentication code: 13

Re: Adding Colorspace and ICC profile after Composite

Post by twaintwist »

Thank you very much for your help ---- there happened to be an sRGB.icc in C:\Program Files\ImageMagick-6.8.7-Q16

And adding it in with -profile worked!

Again --- I really appreciate the help
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Adding Colorspace and ICC profile after Composite

Post by fmw42 »

Glad you found it. I was mistaken about it not coming with Imagemagick.
Post Reply