Download the PHP package rosell-dk/webp-convert-and-serve without Composer

On this page you can find all versions of the php package rosell-dk/webp-convert-and-serve. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package webp-convert-and-serve

WebP Convert and Serve

This library is now part of WebP Convert and thus obsolete!

Build Status

This library can be used for converting and serving WebP images instead of jpeg/png. It is based on WebPConvert, which takes care of the conversion. On top of that, it adds a method for serving the converted image with options on how to handle conversion failures.

The task of serving is in itself actually quite small. It can be implemented in a few lines, like this:

But then comes error handling.

If conversion fails, it will make sense to serve the source image instead (if that exists, that is). For that, we need to inspect the extension in order to provide the correct Content-type header. Also, we want to add headers that tells the browser not to cache it. And what if the source file isn't even available? This should be handled as well. Tedious stuff, that this library takes care of.

API

WebPConvertAndServe::convertAndServe($source, $destination, $options)

Note: This method was added in 0.4.0. The old one, convertAndServeImage() still works, but is depreciated.

Parameter Type Description
$source String Absolute path to source image (only forward slashes allowed)
$destination String Absolute path to converted image (only forward slashes allowed)
$options Array Array of conversion options. See below

The $options argument

The options argument is a named array. WebPConvertAndServe has just two available options (fail and critical-fail). However, the options will be handed over to WebPConvert. So Any option available in webp-convert are available here.

fail

Indicate what to serve, in case of normal conversion failure. Default value: "original"

Possible values Meaning
"original" Serve the original image.
"404" Serve 404 status (not found)
"report-as-image" Serve an image with text explaining the problem
"report" Serve a textual report explaining the problem

Instead of the string values (ie "original"), you can also use the following constants: WebPConvertAndServe::$ORIGINAL, WebPConvertAndServe::$HTTP_404, WebPConvertAndServe::$REPORT_AS_IMAGE and WebPConvertAndServe::$REPORT

critical-fail

Possible values: Same as above, except that "original" is not an option. Default value: "404"

Return value

Number indicating what was served. On fail or critical fail, the value will be one of the following constants: following constants WebPConvertAndServe::$ORIGINAL, WebPConvertAndServe::$HTTP_404, WebPConvertAndServe::$REPORT_AS_IMAGE and WebPConvertAndServe::$REPORT. On success, it will be WebPConvertAndServe::$CONVERTED_IMAGE. All fail constants are negative. The success constant is positive – so you can test success with a if ($returnValue > 0)

Example:

Installing

composer require rosell-dk/webp-convert-and-serve


All versions of webp-convert-and-serve with dependencies

PHP Build Version
Package Version
Requires rosell-dk/webp-convert Version ^1.1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package rosell-dk/webp-convert-and-serve contains the following files

Loading the files please wait ....