Accurate colours?

Skip to first unread message

Edsko de Vries

Jul 9, 2018, 8:28:50 AM7/9/18
to diagrams-discuss
Hi all,

I'm using the cairo backend to generate animations (and tried it with rasterize also, with the same results). I'm using the `bgFrame` combinator to specify a background color for my animation, but the colour in the generated PNGs is off (not by much, but off nonetheless) (when specifying #272727 I get #2B2B2B). Any ideas why this might be happening and how I might address it?



Brent Yorgey

Jul 27, 2018, 12:04:02 PM7/27/18
to Edsko de Vries, diagrams-discuss
Hi Edsko,

Apologies for the long delay in responding.  This is curious.  How exactly do you specify the color #272727, i.e. what functions do you use to construct it?


You received this message because you are subscribed to the Google Groups "diagrams-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit

Edsko de Vries

Jul 31, 2018, 2:06:04 PM7/31/18
Hi Brent,

Thanks for replying. I was specifying this through a new command line flag, which I defined as follows:

newtype Background = Background (Maybe (Colour Double))

instance Parseable Background where
  parser = Opt.option (Opt.str >>= aux) $ mconcat [
        Opt.long "background"
      , "Background color"
      aux :: String -> Opt.ReadM Background
      aux "none" = return $ Background Nothing
      aux str    = Background . Just . fromAlphaColour <$> readHexColor str

and which I then use as follows

backgroundRect :: Background -> Diagram B
backgroundRect (Background background) =
    rect (20 * nodeDiameter) (14 * nodeDiameter)
      # lwO 0
      # maybe id fc background

I worked around the problem by adding a border around the rendered animation (so that the difference between the animation and rest of background on which I was showing it wasn't so obvious). 

Curious little problem! :)


Brent Yorgey

Aug 10, 2018, 4:20:43 PM8/10/18
to Edsko de Vries,
I think ultimately this must have something to do with how the color is read and represented internally (hint: it's not just represented as 3 bytes), and perhaps some kind of color space conversion that is happening when you don't intend it.  I haven't been able to get to the bottom of it though...

Reply all
Reply to author
0 new messages