Image conversion black becomes aqua

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
webdevsoup
Posts: 11
Joined: 2012-08-09T15:15:21-07:00
Authentication code: 67789

Image conversion black becomes aqua

Post by webdevsoup »

Utilizing IMagick commands, we are running some thumbnail commands on .psd, .eps, and .jpg files to convert them to .png. However, some of the images are giving us a problem where the black color becomes an odd aqua color. I have an image example of before:

Image

And once the command is run, it turns in to the following image:

Image

The command being run is the following:

Code: Select all

			$thumb=new Imagick($local_path);
			$thumb->flattenImages();
			
			//Scale the image
			$thumb->thumbnailImage(128,128,true,false);
			$thumb->setImageFormat("png");
			$thumb->stripImage();
			
			//Write the new image to a file
			$thumb->writeImage('/home/metathumbs/'.$image_data->thumb);
Thanks for any help!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image conversion black becomes aqua

Post by fmw42 »

You don't say what version of IM nor platform? There could be a bug in your version of IM.

This works fine for me from the command line on IM 6.7.8.8 Q16 Mac OSX SnowLeopard

convert original.png -thumbnail 128x128 -strip original_proc.png

But the image downloaded was PNG and not EPS etc. It is possible that your EPS or PDF is in CMYK. For that you need to convert to RGB first

convert -colorspace sRGB -density XX original.eps -thumbnail 128x128 -strip original_proc.png

If that does not work, then put a link here to you eps file so we can check or run

identify -verbose original.eps

and post the results
webdevsoup
Posts: 11
Joined: 2012-08-09T15:15:21-07:00
Authentication code: 67789

Re: Image conversion black becomes aqua

Post by webdevsoup »

I apologize, I'm new to ImageMagick. This was set up by someone else, and I am now maintaining because the other individual took a new job.

ImageMagick-6.5.4.7-5.el6.x86_64
Running CentOS 6.0 Final.

I converted the image, and now it is turning up a peach-ish color.

This is all being done via PHP at a command line, but is cycling through a MySQL statement. Full command is here:

Code: Select all

$thumb=new Imagick($local_path);
			$thumb->flattenImages();
			$thumb->setImageColorspace(Imagick::COLORSPACE_SRGB);
			//Scale the image
			$thumb->thumbnailImage(128,128,true,false);
			$thumb->setImageFormat("png");
			$thumb->stripImage();
			
			//Write the new image to a file
			$thumb->writeImage('/home/metathumbs/'.$image_data->thumb);
Image

file is here: http://www.sfwdesign.com/sites/all/files/test.psd
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image conversion black becomes aqua

Post by fmw42 »

You file is CMYKA Photoshop PSD file with two layers. It is not a vector file such as eps, pdf, ps.

IM will convert the file just fine on my IM 6.7.8.8 Q16 Mac OSX SnowLeopard into two PNG images, one for each layer using:

convert -colorspace sRGB test.psd -thumbnail 128x128 -strip test_proc.png

However since it has profiles for U.S. Web Coated (SWOP), you probably will get a better result using profiles such as

convert test.psd -profile Profiles/USWebCoatedSWOP.icc Profiles/sRGB.icc -thumbnail 128x128 -strip test_proc2.png

Using the latter generates three images, but the last one is all white.

You will need to put in your path to your profiles after you locate some.
webdevsoup
Posts: 11
Joined: 2012-08-09T15:15:21-07:00
Authentication code: 67789

Re: Image conversion black becomes aqua

Post by webdevsoup »

The problem is that this is part of a script that cycles through a MySQL database, and some of the files are .eps files, some are .psd files, and some are .jpg files. I never know which is which. So, I would have to write a try >> catch statement, or if >>> then statement to test the extension of each file, which is fine, I can do that. However, I cannot have the background's be white, they MUST be transparent. The files change, and new files are added. There are over 40,000 images that this script can run through, not knowing which extension it is going to be.

The file must be an exact replica of the .eps/.psd/.jpg file it is originating from. If it is not exact, the client will continue to wonder if it is the appropriate image. High-maintenance client this is.
webdevsoup
Posts: 11
Joined: 2012-08-09T15:15:21-07:00
Authentication code: 67789

Re: Image conversion black becomes aqua

Post by webdevsoup »

fmw42 wrote:You file is CMYKA Photoshop PSD file with two layers. It is not a vector file such as eps, pdf, ps.

IM will convert the file just fine on my IM 6.7.8.8 Q16 Mac OSX SnowLeopard into two PNG images, one for each layer using:

convert -colorspace sRGB test.psd -thumbnail 128x128 -strip test_proc.png

However since it has profiles for U.S. Web Coated (SWOP), you probably will get a better result using profiles such as

convert test.psd -profile Profiles/USWebCoatedSWOP.icc Profiles/sRGB.icc -thumbnail 128x128 -strip test_proc2.png

Using the latter generates three images, but the last one is all white.

You will need to put in your path to your profiles after you locate some.
As I stated before, this is in PHP, so I need the PHP command to utilize the convert command. I will continue to search for it, but have had no luck so far. I have the profiles I need.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image conversion black becomes aqua

Post by fmw42 »

Just put the IM command line into a PHP exec() function. See http://www.rubblewebs.co.uk/index.php for examples
webdevsoup
Posts: 11
Joined: 2012-08-09T15:15:21-07:00
Authentication code: 67789

Re: Image conversion black becomes aqua

Post by webdevsoup »

Perhaps I'm not getting the right code in there:

Code: Select all

$thumb = '/home/metathumbs/'.$image_data->thumb;
$cmd = "$local_path -profile /usr/include/ImageMagick/Profiles/CMYK\ Profiles/USWebCoatedSWOP.icc  /usr/include/ImageMagick/Profiles/RGB\ Profiles/sRGB.icc -thumbnail 128x128 -strip ";
exec("convert $cmd $thumb");
Returns the following errors:

Code: Select all

convert: unable to open image `/usr/include/ImageMagick/Profiles/RGB Profiles/sRGB.icc': No such file or directory @ blob.c/OpenBlob/2480.
convert: missing an image filename `/home/metathumbs/HON_SteelBookcases_Group.png' @ convert.c/ConvertImageCommand/2800.
45450 HON_SteelBookcases_Group.psd HON_SteelBookcases_Group.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image conversion black becomes aqua

Post by fmw42 »

$thumb = '/home/metathumbs/'.$image_data->thumb;
$cmd = "$local_path -profile /usr/include/ImageMagick/Profiles/CMYK\ Profiles/USWebCoatedSWOP.icc /usr/include/ImageMagick/Profiles/RGB\ Profiles/sRGB.icc -thumbnail 128x128 -strip ";
exec("convert $cmd $thumb");

What is $local_path?

Note you left in my Profile path in one place and replaced it with yours in another.

Proper IM syntax is usually,

convert input commands output

http://www.imagemagick.org/Usage/basics/#why


I do not think profiles work if specified before the input image

For scripting in PHP, see http://www.rubblewebs.co.uk/index.php
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Image conversion black becomes aqua

Post by Bonzo »

You can have relative paths in your code.

If you are having problems start with something simple ( for instance everthing in the same directory as the code ) and when it works then use variables etc.
webdevsoup
Posts: 11
Joined: 2012-08-09T15:15:21-07:00
Authentication code: 67789

Re: Image conversion black becomes aqua

Post by webdevsoup »

$local_path is the variable where the image we are converting from is stored. It is a linked folder, linked to

Code: Select all

/home/opmasan/metaimage/NAME_OF_FOLDER/NAME_OF_MAN/NAME_OF_FILE
I changed both locations utilizing a specific path.

Code: Select all

-profile 
/usr/include/ImageMagick/Profiles/CMYK\ Profiles/USWebCoatedSWOP.icc  
/usr/include/ImageMagick/Profiles/RGB\ Profiles/sRGB.icc
However, I just noticed that the sRGB.icc Profile wasn't included in the Profiles I downloaded. I will have to go find that specific one.

Thanks for all your continued help to an IM newbie fmw42.

Bonzo, I will try that first to see if I can get it to work. Stepping away for a bit.
webdevsoup
Posts: 11
Joined: 2012-08-09T15:15:21-07:00
Authentication code: 67789

Re: Image conversion black becomes aqua

Post by webdevsoup »

Ok, I was able to convert the image using direct paths. However, the image still does not appear black, although it's extremely close.

Image

Can it get closer? If not, I'll begin substituting variables for my images.

Also, I noticed for this particular image, I actually get 4 .png files. I need it to be 1 .png file. How do I get rid of the others?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Image conversion black becomes aqua

Post by fmw42 »

webdevsoup wrote:Ok, I was able to convert the image using direct paths. However, the image still does not appear black, although it's extremely close.

Image

Can it get closer? If not, I'll begin substituting variables for my images.

Also, I noticed for this particular image, I actually get 4 .png files. I need it to be 1 .png file. How do I get rid of the others?

PSD files can have multiple layers. Usually the first layer is the flattened image. But you can select any layer Try

image.psd[0] in your code to select the first layer.
webdevsoup
Posts: 11
Joined: 2012-08-09T15:15:21-07:00
Authentication code: 67789

Re: Image conversion black becomes aqua

Post by webdevsoup »

fmw42 wrote:
PSD files can have multiple layers. Usually the first layer is the flattened image. But you can select any layer Try

image.psd[0] in your code to select the first layer.
The thing is that I cannot store 3 versions of 43,000 images. That just will not be acceptable.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Image conversion black becomes aqua

Post by Bonzo »

Working on image.psd[0] will only produce one image as it is only working on the one layer.

If you do not use the [0] it will produce an image for every layer.
Post Reply