Wrote this for getting the content of image from the given URL. It accepts a URL and returns an array of shape number_of_channels image_height image_width
. Each "row" represents a pixel, and each element is within the range of 0 to 1.
- What are some issues with my implementation?
- Is there a better way to turn the data from
HttpCommand.Get
into image? - Is there a better way to handle different image format?
- How to make it more portable?
∇ r←GetImg url ;ns
'ns'⎕NS'url'
:With ns
⎕SE.SALT.Load'HttpCommand'
valueOf←{⊃(,¯1↑⍉⍵)/⍨(⊂⍺)≡¨,1↑⍉⍵}
split←{⍵⊆⍨~⍺=⍵}
tmp_path←(⊢2 ⎕NQ # 'GetEnvironment',⊂)'tmp'
res←HttpCommand.Get url
(type fmt)←'/'split'Content-Type'valueOf res.Headers
tmp_ft←(tmp_path,'\tmp.',fmt)(⎕NCREATE⍠('Unique' 1))0
tmp_name←⊃⎕NINFO tmp_ft
res.Data ⎕NREPLACE tmp_ft 0
⎕NUNTIE tmp_ft
'bm'⎕WC'Bitmap'('File'tmp_name)
⎕NDELETE tmp_name
:EndWith
r←255÷⍨256(⊥⍣¯1)ns.bm.CBits
∇