# Unfortunate interaction between ImageCore and Gadfly

**URL:** <https://discourse.julialang.org/t/unfortunate-interaction-between-imagecore-and-gadfly/43287>\
**Category:** Visualization\
**Created:** [July 18, 2020, 2:10pm UTC](https://discourse.julialang.org/t/unfortunate-interaction-between-imagecore-and-gadfly/43287 "2020-07-18T14:10:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![NicholasWMRitchie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nicholaswmritchie/32/22449_2.png) [@NicholasWMRitchie](https://discourse.julialang.org/u/NicholasWMRitchie)\
**Post date:** [July 18, 2020, 2:10pm UTC](https://discourse.julialang.org/t/unfortunate-interaction-between-imagecore-and-gadfly/43287/1 "2020-07-18T14:10:10Z")

</div>

I’ve discovered an unfortunate interaction in which just loading ImageCore causes Gadfly to fail. This took me days to debug ☹ as initially I assumed the error was in my code. It was only when I guessed that the problem was in Images and stripped out all references to Images that I started to make progress.

```julia
using Gadfly
using Colors

curves = 1:3

const palette = distinguishable_colors(
    length(curves)+3,
    [RGB(253 / 255, 253 / 255, 241 / 255), RGB(0, 0, 0), colorant"DodgerBlue4"],
    transform = deuteranopic,
)[3:end]

ls = [layer(x=1:10, y=map(x->x^i, 1:10), Geom.line, Theme(default_color = palette[i] )) for i in curves ]
# Succeeds
plot(ls..., Guide.manual_color_key("Curves", ["Curve $i" for i in curves], palette[curves]))

println("Loading ImageCore")
using ImageCore
# Fails on the second plot...
plot(ls..., Guide.manual_color_key("Curves", ["Curve $i" for i in curves], palette[curves]))

```

The problem is the line in [ImageCore/convert\_reinterpret.jl](https://github.com/JuliaImages/ImageCore.jl/blob/master/src/convert_reinterpret.jl) line 80-83

```julia
function Base.convert(::Type{Array{Cdest,n}},
                      img::AbstractArray{Csrc,n}) where {Cdest<:Colorant,n,Csrc<:Colorant}
    copyto!(Array{ccolor(Cdest, Csrc)}(undef, size(img)), img)
end

```

This leads to this error:

```julia
ERROR: LoadError: TypeError: in new, expected Array{Colorant,1}, got a value of type Array{RGB{Float64},1}
Stacktrace:
 [1] ManualDiscreteKey at C:\Users\nritchie\.julia\dev\Gadfly\src\guide\keys.jl:267 [inlined]
 [2] Gadfly.Guide.ManualDiscreteKey(; title::String, labels::Array{String,1}, pos::Array{Any,1}, color::Array{RGB{Float64},1}, shape::Array{Function,1}, size::Array{Measures.Measure,1}) at C:\Users\nritchie\.julia\dev\Gadfly\src\guide\keys.jl:295
 [3] #manual_color_key#131 at C:\Users\nritchie\.julia\dev\Gadfly\src\guide\keys.jl:321 [inlined]
 [4] manual_color_key(::String, ::Array{String,1}, ::Array{RGB{Float64},1}) at C:\Users\nritchie\.julia\dev\Gadfly\src\guide\keys.jl:321
 [5] top-level scope at c:\users\nritchie\.julia\dev\NeXLDatabase\weave\testgadfly.jl:18
 [6] include(::String) at .\client.jl:457
 [7] top-level scope at REPL[1]:1
in expression starting at c:\users\nritchie\.julia\dev\NeXLDatabase\weave\testgadfly.jl:18

```

One would like to be able to assume that libraries are largely independent of each other and that there is no chance of one library breaking another. However, this may be baked into the dynamic design of the Julia language.

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [July 18, 2020, 3:39pm UTC](https://discourse.julialang.org/t/unfortunate-interaction-between-imagecore-and-gadfly/43287/2 "2020-07-18T15:39:36Z")

</div>

This is partly a type-piracy problem, which package authors usually avoid. The situation which inspired the piratical implementation in ImageCore has changed; it is unfortunate that you encountered a bad side effect before it could be replaced.

Tim drafted a correction last month:  
[https://github.com/JuliaImages/ImageCore.jl/pull/131](https://github.com/JuliaImages/ImageCore.jl/pull/131)
