One of my latest projects requires an image server which had to fulfill these two API requirements:
- Storing: Accept a URL as an image source then provide a token to address the cached/stored image.
- Reading: Accept a token to provide an image in a specified resolution and/or format.
- The read API should provide a method to crop and resize images.
- For the purposes of my project, I require the machine to...
- accept JPEG, GIF, PNG, and SVG
- only serve JPG's
Download
The code is on GitHub. Download and modify as you please.
Basic API format
- Storing:
/store/secret-key/base64_encoded_URL
- Reading:
/key/token/size
Storing an Image
Calling the API with parameters something like this:
Where store is the action, 123 is the secret key to store images, and the last parameter is the base64 encoded result of "https://upload.wikimedia.org/wikipedia/commons/b/b0/NewTux.svg"Should result in JSON looking something like this: The above means that the imageserver has decoded the URL, downloaded it, saved it in JPEG format (configurable), and returned a key for you to address that image in the future. The key is simply a hash of the URL passed in.
Reading an Image
Calling the API with parameters something like this (using the token from above):
Demo Settings File
My Experience on a Hosted Solution
I use the GridService product offered by MediaTemple for my hosting. I followed this article to get the ImageMagick PECL working. But ended up discovering that the extension was quite limited compared to the native console convert. So I fell back to using PHP's exec.
1 comment:
As a programmer, there is a tool, I would like to suggest, that tool is
url-decode.com/tool/base64-encode
That link also contains the tool, related to encode and decode (URL, base64), converter, developer tools, IP related tools, and many more. You must check it out.
Post a Comment