Download the PHP package mirador/mirador without Composer
On this page you can find all versions of the php package mirador/mirador. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mirador/mirador
More information about mirador/mirador
Files in mirador/mirador
Package mirador
Short Description Official Mirador PHP Client
License MIT
Homepage https://github.com/mirador-cv/mirador-php
Informations about the package mirador
Mirador-PHP
A php client for the Mirador Image Moderation API. To get started, you will need an API Key, available at mirador.im. For questions about keys or support with this module please email [email protected].
Installation
The module is available on Packagist, and can be installed with composer (in your composer.json):
Getting Started
Examples
To see some simple usage, check out our examples.
Classifying Files
The php client supports working with a number of data types:
- filenames classifyFiles
SplFileInfo
objects and subclasses (e.g., SplFileObject) classifyFiles- base64-encoded data URIs, as in those provided by Javascript
FileReader
orCanvasElement
APIs. classifyDataUris. - file contents (e.g., output of
file_get_contents()
) classifyBuffers
Every method has an associated single-request method, e.g., classifyFile for classifyFiles. These have a similar interface but only support processing of one item at a time.
\Mirador\API\Client#classifyFiles
All classification methods share an identical interface that allows for generally flexible input. The mirador API, and the object returned by the API allow for the attribution of an arbitrary identifier to your requests, to make post-processing of results easier. However, in cases where you do not specify an ID, the client will choose one (in a way that generally makes sense).
A very simple way to classify files is by filename:
Alternatively, you can specify an id by passing in an associative array:
It's pretty easy to use this method with the $_FILES
superglobal:
Working with SplFileInfo
and Subclasses
classifyFiles
also accepts SplFileInfo
objects and subclasses (e.g., Symfony/Laravel's UploadedFile
). When an id is not specified, the output of SplFileInfo::getPathname()
is used as the id:
\Mirador\API\Client#classifyFile
As in the other classification methods, classifyFiles has a corresponding single-request method, classifyFile. This can be used with the same interface as its multiple-request sibling:
Since the result is returned directly, any exceptions will be thrown instead of being available in an errors
array:
\Mirador\API\Client#classifyBuffers
This has an identical usage/interface to classifyFiles, except that instead of passing in filenames or file objects, you only provide already-read buffers.
This method is useful when working with a library that only gives access to POST
or PUT
bodies, e.g., Slim framework's $app->request()->getBody()
.
When not explicitly specifying an ID, the client uses the index of the item in the parameters, since we can't derive a name from a file buffer:
For this reason, when working with buffers, it's good to specify an id (if you can):
\Mirador\API\Client#classifyBuffer
This is a simple helper when only classifying one buffer, it returns a \Mirador\API\Result
object or throws \Mirador\API\RequestException
on error:
\Mirador\API\Client#classifyDataUris
This method exists as a convenience for simplified client-server communication when using clients that work with data uris (e.g., in web applications). For example, given this javascript (using jQuery to be concise):
We could handle that request on the server with this code:
This example shows the singular, classifyDataUri
, however, the multiple -- classifyDataUris
, has an identical interface.
Classifying Urls
There are a couple of requirements to be mindful of when classifying urls, they must meet the following criteria:
- be publically-accessibly
- have a correctly set mimetype (
image/*
) - not require query paramters
Given that, the interface for classifying urls is identical to that when using classifyFiles
\Mirador\API\Client#classifyUrls
Since urls are text and are generally short, our client uses the url as an id by default:
However, as with classifying files, an id can be specified by passing an array:
\Mirador\API\Client#classifyUrl
As with the other methods/data types, you can also classify a single url using the convenience method classifyUrl
. This will return a \Mirador\API\Result object or throw a \Mirador\API\RequestException:
\Mirador\API\Result
The \Mirador\API\Result
object reprents the classification result for a single image/url. It has the following properties:
id
[string|int]
- a unique identifier for the resultsafe
[boolean]
- indicates if an image contains adult content.value
[float 0.0-1.0]
- the likelyhood that the image does contain adult content (for implementing a custom threshold)
Method Output/Results
Multiple-request methods (e.g., classifyUrls
) return an object with two properties:
results
[Array of Mirador\API\Result] results, indexed byid
errors
[Array of Mirador\API\RequestException] exceptions; can be thrown
Contributing / Issues
Please submit any issues as issues here on github, feel free to submit a pull request, or for immediate support, contact us at [email protected]. #