Detect and convert CMYK jpg images to RGB

Does anyone have a php script that will not only detect if a jpg image is CMYK, but will also convert it to RGB if found?

Thanks!!

LN
LVL 9
LinuxNubbAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

stormistCommented:
LinuxNubbAuthor Commented:
Very nice article, but it doesn't have anything that about detecting if an image is already cmyk, and converting it.

I basically want to see if an image is cmyk, and if it is then convert it to rgb.  Any more ideas?
stormistCommented:
You can use ImageMagick. Here:
http://www.imagemagick.org/script/command-line-processing.php

this is a command line tool that you can access from PHP.. I believe specifically the command you are looking for is:

convert -colorspace RGB oldcymk.jpg jpg:newrgb.jpg

so in php you'd run exec('convert -colorspace RGB oldcymk.jpg jpg:newrgb.jpg');

I believe it will leave it alone if the image does not need conversion. See how that works for you?

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Marcus BointonCommented:
Stormist is right. There's another option for identifying the image format in the first place though - ImageMagick has an identify function:

http://www.imagemagick.org/script/identify.php

Probably best to use that before trying to convert images that don't need converting.
LinuxNubbAuthor Commented:
Very good.  So there is a way, but not natively.

Thanks Gents!
Marcus BointonCommented:
There is an ImageMagick PHP extension in PECL that makes these functions native, but it's been stagnant for years: http://pecl.php.net/package/imagick You're better off using the exec() approach. I wouldn't want to do image processing stuff in PHP itself.
LinuxNubbAuthor Commented:
It's not real intensive, so it wouldn't be too bad.  It's basically if a someone uploads a CMYK image, which should not happen often at all, to detect it and convert it.

Thanks for the info though again.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.