libvips / ruby-vips

Ruby extension for the libvips image processing library.
MIT License
822 stars 61 forks source link

Convert CMYK to RGB? #61

Closed ioquatix closed 9 years ago

ioquatix commented 9 years ago

Is this possible, and if so how?

jcupitt commented 9 years ago

Hi, you need the icc_import functions to import from CMYK device space with an ICC profile:

http://0.0.0.0:8808/doc_root/ruby-vips-0.3.9/rdoc/VIPS/Image.html#method-i-icc_import

For some reason I don't understand ruby-gems won't generate docs for C extensions, but you should find the docs on your local gem server.

Use something like:

#!/usr/bin/ruby

require 'rubygems'
require 'vips'

im = VIPS::Image.new(ARGV[0], :sequential => true)

# import to CIELAB with lcms
lab = nil

# try with the embedded profile
begin
    puts "trying with embedded profile ..."
    lab = im.icc_import_embedded(:relative)
rescue VIPS::Error
end

# try with the supplied profile
if not lab then
    begin
        puts "trying with supplied profile ..."
        lab = im.icc_import(ARGV[1], :relative)
    rescue VIPS::Error
    end
end

# nope again, fall back to the vips converter
if not lab then
    puts "falling back to vips ..."
    lab = im.srgb_to_xyz.xyz_to_lab
end

# now export to srgb
srgb = lab.lab_to_xyz.xyz_to_srgb

im.write(ARGV[2])

vips8 makes this much nicer, but the new ruby binding isn't done yet.

ioquatix commented 9 years ago

Nice, thanks.