SYMBOL: types
types [ H{ } clone ] initialize
+: (image-class) ( type -- class )
+ >lower types get ?at [ unknown-image-extension ] unless ;
+
: image-class ( path -- class )
- file-extension >lower types get ?at
- [ unknown-image-extension ] unless ;
+ file-extension (image-class) ;
: open-image-file ( path -- stream )
binary <limited-file-reader> ;
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: http.client images.loader images.loader.private kernel
-images.viewer ;
+USING: accessors assocs http.client images.loader
+images.loader.private images.viewer io.pathnames kernel
+namespaces sequences ;
IN: images.http
+<PRIVATE
+
+: content-type ( response -- type/f )
+ content-type>> dup "image/" head?
+ [ 6 tail ] [ drop f ] if ;
+
+PRIVATE>
+
: load-http-image ( path -- image )
- [ http-get nip ] [ image-class ] bi load-image* ;
+ [ http-get swap content-type ] [ file-extension ] bi or
+ (image-class) load-image* ;
: http-image. ( path -- )
load-http-image image. ;