Basics to process Images

It’s time to start with image processing but if you still don’t know how to create a project and authenticate it please refer to the Getting started guide

The image processing workflow with iLoveIMG API is very simple for all its tools. Consists of four basic instructions: 1) Start task, 2) Upload files, 3) Process files and 4) Download files. Once the API have executed these steps, you should have your image files processed by your desired tool and downloaded anywhere you like.

The iLoveIMG API offers many options and custom functions for every tool but for now we will focus only on how to perform a simple task with very few code lines. Once you are done with this guide we recommend you to take a look on the common attributes you can set on any task in the Common features guide.

Start task

To start a new task you need to create it with the function newTask(). This will check which server is assigned to your task and create it. You can do this by simply assign which tool of the many that iLoveIMG API offers to process images we want to execute on our files. For this example we will compress our three files:

Download the PHP library from GitHub

Please note that the first line is set to authenticate our project with the API servers and that you only need to authenticate once per project, not for every task you create. With the following two lines you will start and process your task respectively.

Upload files

The next step is to assign all the files that you (or your users) want to upload by adding these files to the task like in this code example:

Download the PHP library from GitHub

The example adds a file path to the task along with the name of three files to upload and the addFile() function will upload them automatically. In further guides you will see that is also possible to upload files from URL with dedicated functions.

Process files

Now it’s time to execute your process:

Download the PHP library from GitHub

Download

Finally assign the download action to the task to download your files.

Congratulations! You have compressed three images in only 9 lines of code.

Download the PHP library from GitHub

Full code

And this is how the full code looks like:

Download the PHP library from GitHub

Open tasks limitation

Due to security matters and to avoid an overflow of API requests, you must know that there is a limitation to the maximum tasks that can be opened at a time according to a 10% of your monthly file limit subscription. A task is opened since you upload a file and until you process it. Usually you won’t have many open tasks at the same time as long as you process immediately all your uploaded files. Take into account this limitation for possible code and or design errors of your apps.

Test a library

You can download this example here in any of the compatible API languages.

Now you’re ready to visit our Common features guide for a more advanced usage of image processing tools.