Common functions

If you have read the Basics to process Images guide, you already know the very basics to process an image with the API. Now you will learn how to execute common functions for all API tools and set attributes, some of them, while not essential, can be very helpful to use for the Upload, Process and Download instructions.

Functions and attributes for Upload

You can upload files from the following storage types:

  • Local
  • Web

Upload from local

For local files you must use addFile() function and it is mandatory to set always local path filename to upload.

Download the PHP library from GitHub

Upload from Web

Upload from Web works exactly the same as from local, only need to set an URL on an addURLFile() function.

Download the PHP library from GitHub

File attributes

You can set rotation attribute:

Download the PHP library from GitHub

Rotate a file

It's possible to rotate the orientation of any uploaded file by using setRotation() function with one of four directions parameters (Up = 0, Right = 90, Down = 180, Left = 270);

Delete files

You may need to delete previously uploaded files from a task. In this case use the following delete function:

Download the PHP library from GitHub

Advanced processing

You have seen how to process images in a very basic way before. In addition, processing instructions have some advanced options to consider. Some of them are specific to a tool and others are common to all of them. Here we will focus on those common options to all the tools.

Example code:

Download the PHP library from GitHub

Ignore file errors

Some of the uploaded files may be damaged and won’t be able to process. setIgnoreErrors(boolean) allows to ignore those damaged files and force the task to process the good ones.

Tasks have setIgnoreErrors(true) by default so you won’t need this function unless you want to force an error message for any damaged file.

Try file to repair a damaged image

One of the newest ILoveIMG features is the possibility to repair damaged image files. By default the API tries to repair any damaged file but it is allowed to disable this behaviour with:

Download the PHP library from GitHub

Set output filename

As a rule, the output filename of files will be the same as the input filename in many cases. Some others depend on the used tool. But you can also customize the output filename with setOutputFilename()

This function accepts a single string to the filename besides the following predefined vars:

{filename}=original filename
{n}=file number
{date}=current date
{tool}=the current processing action

So the final output name could be:

Download the PHP library from GitHub

Set a package filename

iLoveIMG API will always pack multiple output files in a single compressed file. You can set this package filename with setPackageFilename() adn the following predefined vars:

{filename}=original filename
{date}=current date
{tool}=the current processing action

So the final output name could be:

Download the PHP library from GitHub

Functions for download

Download functions are exactly the same that the basic upload functions and allows you to download your output files to local with downloadLocal().

Download the PHP library from GitHub

Now that you know all the common advanced features for Upload, Process and Download instructions you are ready to dive into the functioning of the iLoveIMG Tools.