Webthumb Bluga.net is a great reliable online thumbnail webservice (I tried some others and find they were frequently disconnected). I have used this service to create these thumbnails on the Companies Page. They above all offer a free web service up to 100 request per month for any registered user. They have a REST API specification named easythumb I reproduced below for convenience:
Specification
- Endpoint: http://webthumb.bluga.net/easythumb.php
- Parameters:
- user: Your Webthumb user_id available on your user page
- url: Site to thumbnail, make sure to urlencode this
- size: Size of the thumbnail to return
small,medium1,medium2,large - cache: The # of days old a cached version of the thumbnail can be - 1 to 30
- hash: The security hash components are covered below
Security Hash
The security hash is an md5 hash encoded in hexidecimal containing the following concatenated together
- current date: The current date in GMT/UTC formated as YYYYmmdd (in PHP this is the gmdate function)
- url: The url to thumbnail not urlencoded
- apikey: Your Bluga.net apikey
Example
Any example request looks like:
http://webthumb.bluga.net/easythumb.php?user=1&url=webthumb.bluga.net%2Fhome&hash=80a171c61c04084ba55cade47ce8d303&size=medium&cache=1
Let’s translate the spec into Rebol. The spec is saying the REST url is the concatenation of Endpoint, User, Url in encoded form and a hash code (will see just after) that is:
do http://reboltutorial.com/source/encode-url.r
REST-url: rejoin [Endpoint "?" "user=" user "&" url "=" (encode-url url) "&" "hash=" hash]
where (if we continue to just follow the spec):
gmt: now - now/zone
hash: checksum/method rejoin [gmt/year pad-zero gmt/month pad-zero gmt/day url apikey] 'MD5
Amazingly Rebol can easily generate the GMT components as well as do MD5 encryption with its checksum/method !
pad-zero is just a helper function:
pad-zero: func [ num ] [ either = 1 length? to-string num [ join "0" num ] [ num ] ]
Let’s test; first copy and paste the code below (you must register for free to get your user id and apikey number):
ask-parameters: [
user: ask "User: "
apikey: ask "ApiKey: "
url: ask "Website Url (without http): "
]
do ask-parameters
To get your key registration login and copy these values:
![]()
Then paste the next instructions:
Endpoint: http://webthumb.bluga.net/easythumb.php
thumb-size: pick ["small" "medium" "medium1" "medium2" "large"] 4
pad-zero: func [ num ] [ either = 1 length? to-string num [ join "0" num ] [ num ] ]
gmt: now - now/zone
string-to-hash: rejoin [gmt/year pad-zero gmt/month pad-zero gmt/day url apikey]
hash: checksum/method string-to-hash 'MD5
do http://reboltutorial.com/source/encode-url.r
REST-url: to-url rejoin [Endpoint "?&size=" thumb-size "&" "user=" user "&" "url=" (encode-url url) "&" "hash=" hash]
write clipboard:// REST-url
;launch your default browser
Browse REST-url

Something wrong with the hash code maybe ?

First the type is not a string so we have to fix it with
hash-string: pick parse/all mold hash {#{}} 3
do http://reboltutorial.com/source/encode-url.r
REST-url: to-url rejoin [Endpoint "?&size=" thumb-size "&" "user=" user "&" "url=" (encode-url url) "&" "hash=" hash-string]
If you test again, it still doesn’t work. So let’s go to this online MD5 site and paste the content of string-to-hash by typing in rebol console:
;debug string-to-hash
write clipboard:// string-to-hash
The diffence is just Upper/Lowercase so to fix it, we just need to add
hash-string: lowercase hash-string
Here’s the final code:
;============================
ask-parameters: [
user: ask "User: "
apikey: ask "ApiKey: "
url: ask "Website Url (without http): "
]
do ask-parameters
;=== Copy above first to clipboard if testing ===
Endpoint: http://webthumb.bluga.net/easythumb.php
thumb-size: pick ["small" "medium" "medium1" "medium2" "large"] 4
pad-zero: func [ num ] [ either = 1 length? to-string num [ join "0" num ] [ num ] ]
gmt: now - now/zone
string-to-hash: rejoin [gmt/year pad-zero gmt/month pad-zero gmt/day url apikey]
hash: checksum/method string-to-hash 'MD5
hash-string: pick parse/all mold hash {#{}} 3
hash-string: lowercase hash-string
do http://reboltutorial.com/source/encode-url.r
REST-url: to-url rejoin [Endpoint "?&size=" thumb-size "&" "user=" user "&" "url=" (encode-url url) "&" "hash=" hash-string]
write clipboard:// REST-url
;if you want to save in a directory:
;write/binary to-rebol-file ["c:thumbnails" ask "file name: "] read/binary REST-url
window: [image load REST-url]
view/title layout window "Thumbnail REST Web Service Client"
















