RMagick: Convert CMYK EPS to RGB PNG maintaining transparent background
Asked Answered
C

1

4

I've spent a long time trying to go from a CMYK EPS to a RGB PNG using RMagick and Rails. Hopefully this will be of use to someone:

def convert_image_from_cmyk_to_rgb( image )
  #puts image.alpha?
  if image.colorspace == Magick::CMYKColorspace
    image.strip!
    image.add_profile("#{Rails.root}/lib/USWebCoatedSWOP.icc")
    image.colorspace == Magick::SRGBColorspace
    image.add_profile("#{Rails.root}/lib/sRGB.icc")
  end
  image
end

You can download the ICC files direct from Adobe at http://www.adobe.com/support/downloads/iccprofiles/iccprofiles_win.html

The only thing I haven't been able to suss is how to maintain transparency. The EPS I want to use has a transparent background which is being turned into white. Unfortunately I can't do something like image.transparent( "white" ) as I have white in the image that I want to keep as white.

If I uncomment the puts image.alpha? in the above code it returns false.

Does anyone know if what I'm trying to do is possible with the current version of RMagick, as I'm beginning to wonder if importing CMYK EPSs with transparency isn't supported.

Thanks!

Cymophane answered 26/7, 2011 at 16:39 Comment(1)
Have you considered painting the page something other than white, then set the transparency to that color? TV uses "green screen", rather than white screen because green is a color which is not used.Purkey
A
0

do you know about the paint_transparent command for RMagick?

image.paint_transparent(color, opacity=TransparentOpacity, invert=false, fuzz=img.fuzz) -> image

Description Changes the opacity value of all the pixels that match color to the value specified by opacity. If invert is true, changes the pixels that don't match color.

Arguments

color Either a color name or a pixel.

opacity The new opacity value, either an opacity value or a number between 0 and QuantumRange. The default is TransparentOpacity.

invert If true, changes all the pixels that are not the target color.

fuzz By default the pixel must match exactly, but you can specify a tolerance level by passing a positive value.

Returns A new image

Magick API TransparentPaintImage

Have you seen this video of railscasts http://railscasts.com/episodes/374-image-manipulation ? He uses the github logo to create a stamp with transparency.

Arm answered 5/10, 2013 at 21:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.