# How do I load an image from an array

**URL:** https://discourse.julialang.org/t/how-do-i-load-an-image-from-an-array/24382
**Category:** General Usage
**Created:** [May 19, 2019, 5:41pm UTC](https://discourse.julialang.org/t/how-do-i-load-an-image-from-an-array/24382 "2019-05-19T17:41:39Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![xor0110](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xor0110/32/7926_2.png) [@xor0110](https://discourse.julialang.org/u/xor0110)
#### Post date: [May 19, 2019, 5:41pm UTC](https://discourse.julialang.org/t/how-do-i-load-an-image-from-an-array/24382/1 "2019-05-19T17:41:39Z")

</div>

I have a JPEG encoded image that I loaded from the web using `HTTP.get`. How do I decode it using `FileIO.load`?

I would like to know both how to deal with data in an array instead of in the file system, and whether there’s a better way to load images straight from the web.

---

<div class="post-metadata">

### Author: ![cserteGT3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/csertegt3/32/8283_2.png) [@cserteGT3](https://discourse.julialang.org/u/cserteGT3)
#### Post date: [May 19, 2019, 8:59pm UTC](https://discourse.julialang.org/t/how-do-i-load-an-image-from-an-array/24382/2 "2019-05-19T20:59:30Z")

</div>

I think [Images.jl](https://juliaimages.org/latest/) is what you’re looking for, the [Loading your first image](https://juliaimages.org/latest/install/#Loading-your-first-image-1) section describes how to load an image from file.

---

<div class="post-metadata">

### Author: ![xor0110](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xor0110/32/7926_2.png) [@xor0110](https://discourse.julialang.org/u/xor0110)
#### Post date: [May 22, 2019, 3:05pm UTC](https://discourse.julialang.org/t/how-do-i-load-an-image-from-an-array/24382/3 "2019-05-22T15:05:24Z")

</div>

Thanks, but the idea is that I already have the data in memory and I want to decompress it straight from the array, avoiding to store it in a file first.

---

<div class="post-metadata">

### Author: ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)
#### Post date: [May 22, 2019, 3:20pm UTC](https://discourse.julialang.org/t/how-do-i-load-an-image-from-an-array/24382/4 "2019-05-22T15:20:37Z")

</div>

It’s a bit awkward, but this should work:

```nohighlight
using ImageMagick, ImageShow

bytes = read(joinpath(homedir(), "Desktop", "profile.jpg"))

ImageMagick.load_(bytes)

```

---

<div class="post-metadata">

### Author: ![xor0110](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xor0110/32/7926_2.png) [@xor0110](https://discourse.julialang.org/u/xor0110)
#### Post date: [May 22, 2019, 5:53pm UTC](https://discourse.julialang.org/t/how-do-i-load-an-image-from-an-array/24382/5 "2019-05-22T17:53:22Z")

</div>

Works like a charm, thanks a lot! No idea how I missed it!

---

<div class="post-metadata">

### Author: ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)
#### Post date: [May 22, 2019, 9:43pm UTC](https://discourse.julialang.org/t/how-do-i-load-an-image-from-an-array/24382/6 "2019-05-22T21:43:00Z")

</div>

Well, it’s an internal interface and pretty hidden 😉 FileIO should just support loading from `Vector{UInt8}`^^

---

<div class="post-metadata">

### Author: ![encendre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/encendre/32/21893_2.png) [@encendre](https://discourse.julialang.org/u/encendre)
#### Post date: [February 11, 2021, 11:27am UTC](https://discourse.julialang.org/t/how-do-i-load-an-image-from-an-array/24382/7 "2021-02-11T11:27:12Z")

</div>

The following works for me

```julia
HTTP.get(url).body |> IOBuffer |> load

```

Tested with jpg and png, but maybe in some cases the format cannot be inferred and in this case the extension or the content-type should be used to determine the format.
