Download the PHP package townsymush/ewww-client without Composer
On this page you can find all versions of the php package townsymush/ewww-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download townsymush/ewww-client
More information about townsymush/ewww-client
Files in townsymush/ewww-client
Package ewww-client
Short Description A client to use for connecting to the ewww API and converting images
License MIT
Homepage https://github.com/townsymush/ewww-client
Informations about the package ewww-client
Ewww.io Client
This client is a helper for using the ewww.io api for converting images to png, webp and optimising for use on the web.
To use ewww.io you require a api-key. Visit https://ewww.io to make an account
Please note that any functionality for ewww.io is entirely ewww.io's responsibility, this package is just a helper to use their API.
To install this package through composer
Usage
Create new instance of the converter The converter requires your api key as a string and a Guzzle Client to make the API requests
To convert/optimise and image you need to make a Job
to process. There are two jobs WebPJob
and FileJob
WebPJob
A WebPJob
is used to convert an image (png, jpg) to a webp
file.
Create job
If the file cannot be opened an exception will be thrown.
Set height and width (optional)
If you want to change height and width of image. You must set both on the job. The methods accept an integer which will set the image sizes in pixels
Set image quality (optional)
If you want to change the quality of the image set the quality with the following method. note the default is set at 82
FileJob
This job is used to optimise and image or convert a jpg
or gif
to png
.
Create job
If the file cannot be opened an exception will be thrown.
Set image quality (optional)
If you want to change the quality of the image set the quality with the following method.
note the default is set at 82 and this is only in effect is convert
is set to true
when processing PNG
images.
Preserve metadata (optional)
To preserve metadata in the image file set the metadata
to true
.
Note: Default is false
Lossy compression (optional) (Recommended)
To set lossy compression for higher compression with minimal quality loss
Note: Default is false
Convert file (optional)
To convert the file type set this to true
. It enables the conversion mode on the ewww.io API
request (JPG
to PNG
, PNG
to JPG
or GIF
to PNG
)
Processing a job example
Once a job has been created, the next step is to process that job with the converter.
Worth noting
Unfortunately the ewww.io API does not return error status codes which could make the client throw an exception. If the api request failed you will need to inspect the response for the error message.
We are assuming that you will have validated your image before sending it through the ewww.io api. This package does not validate the image types being processed.
Tests
We have written some tests as part of this package which you can run by running
./vendor/bin/phpunit
while in the project directory. You will need o add your api-key
to the tests and remember this will use some of your pre-paid credits on your ewww.io account.