Download the PHP package imageoptim/imageoptim without Composer

On this page you can find all versions of the php package imageoptim/imageoptim. 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 imageoptim

ImageOptim API PHP client

This library allows you to resize and optimize images using ImageOptim API.

ImageOptim offers advanced compression, high-DPI/responsive image mode, and color profile support that are much better than PHP's built-in image resizing functions.

Installation

The easiest is to use PHP Composer:

If you don't use Composer, then require or autoload files from the src directory.

Usage

First, register to use the API.

There's a longer example at the end of the readme.

Methods

API($username) constructor

new ImageOptim\API("your api username goes here");

Creates new instance of the API. You need to give it your username.

imageFromPath($filePath) — local source image

Creates a new request that will upload the image to the API, and then resize and optimize it. The upload method is necessary for optimizing files that are not on the web (e.g. localhost, files in /tmp).

For images that have a public URLs (e.g. published on a website) it's faster to use the URL method instead:

imageFromURL($url) — remote source image

Creates a new request that will read the image from the given public URL, and then resize and optimize it.

Please pass full absolute URL to images on your website.

Ideally you should supply source image at very high quality (e.g. JPEG saved at 99%), so that ImageOptim can adjust quality itself. If source images you provide are already saved at low quality, ImageOptim will not be able to make them look better.

resize($width, $height = optional, $fit = optional) — desired dimensions

If you don't call resize(), then the original image size will be preserved.

See options reference for more resizing options.

dpr($x) — pixel doubling for responsive images (HTML srcset)

The default is dpr(1), which means image is for regular displays, and resize() does the obvious thing you'd expect.

If you set dpr(2) then pixel width and height of the image will be doubled to match density of "2x" displays. This is better than resize($width*2), because it also adjusts sharpness and image quality to be optimal for high-DPI displays.

See options reference for explanation how DPR works.

quality($preset) — if you need even smaller or extra sharp images

Quality is set as a string, and can be low, medium or high. The default is medium and should be good enough for most cases.

getBytes() — get the resized image

Makes request to ImageOptim API and returns optimized image as a string. You should save that to your server's disk.

ImageOptim performs optimizations that sometimes may take a few seconds, so instead of converting images on the fly on every request, you should convert them once and keep them.

apiURL() — debug or use another HTTPS client

Returns string with URL to https://im2.io/… that is equivalent of the options set. You can open this URL in your web browser to get more information about it. Or you can make a POST request to it to download the image yourself, if you don't want to use the getBytes() method.

Error handling

All methods throw on error. You can expect the following exception subclasses:

If you're writing a script that processes a large number of images in one go, don't launch it from a web browser, as it will likely time out. It's best to launch such scripts via CLI (e.g. via SSH).

Help and info

See imageoptim.com/api for documentation and contact info. I'm happy to help!

Example

This is a script that optimizes an image. Such script usually would be ran when a new image is uploaded to the server. You don't need to run any PHP code to serve optimized images.

The API operates on a single image at a time. When you want to generate multiple image sizes/thumbnails, repeat the whole procedure for each image at each size.


All versions of imageoptim with dependencies

PHP Build Version
Package Version
Requires php Version ^5.4 || ^7.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 imageoptim/imageoptim contains the following files

Loading the files please wait ....