API Requests


Shortcodes are not the only method for accessing IMG Processor functions and displaying results. The plugin also provides an API that functions directly within the src attribute of any <img/> tag. The following statements are equivalent.

  • <img src="image.jpg" />
  • <img src="/wp-content/plugins/tenandtwo-img-processor/api.php?source=image.jpg" />

Normally, the src attribute of an <img/> specifies a URL for an image file. When using the IMG Processor API, that URL is passed as the source parameter instead. If the source image is missing or can’t be found, the configured Placeholder Image is shown, not a broken image.

After the required source parameter, the IMG Processor API accepts the same arguments as the [img_process/] shortcode. For instance, an image can be resized by appending &transform=fit&height=300 to the request.

Note: API requests are sent by users as pages are loaded into their browsers. To work properly, api.php must be public. A malicious actor, however, could use this to overwhelm the site with API transform requests. If you are not using this plugin feature – ie, not serving images to other sites, and not serving images to non-Wordpress sections of your own site – it should be disabled in IMG Processor Settings > Activate API.


output_nocache

There is one (1) option that is unique to the IMG Processor API: output_nocache. Because the API streams image data directly to the page, there is an option to bypass the usual cache process. The image can be transformed and returned immediately, without creating a new image file. Simply append &output_nocache=1 to the URL.

<img src="/wp-content/plugins/tenandtwo-img-processor/api.php?source=atest.gif&transform=fit&height=200&output_nocache=1" />