Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.
/ smushit Public archive

PHP-API for the well known Smush.it™ image optimizer.

License

Notifications You must be signed in to change notification settings

olafnorge/smushit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

Smush.it™ PHP-API

The SmushitApi is a nice tool to pass your images to Smush.it™. It supports posting local files and passing remote files like implemented on the Smush.it™ website. It also provides the ability to download the optimized images as a ZIP file directly from Smush.it™. This is the biggest advantage in comparison to all the other Smush.it™-APIs at github.com.

  • Fast
  • No configuration needed.

Usage

$files = scandir('./image_folder');

try {
	/* @var $SmushitApi SmushitApi */
	$SmushitApi = new SmushitApi();
				
	if (!$SmushitApi->optimize($files) || !$SmushitApi->getImageCount()) {
		throw new Exception('SmushitApi returned errornous.');
	}
				
	/* @var $SmushitImage SmushitImage */
	foreach ($SmushitApi->getImages() as $SmushitImage) {
		if (!$SmushitImage->hasError()) {
			$binaryData = $SmushitImage->getDstBinaryData();
			// do something with the optimized image
		}
	}
} catch (Exception $Exception) {
	$message = $Exception->getMessage();
	$stack = $Exception->getTraceAsString();
	trigger_error("Can not smush image. Message: {$message}\nStack: {$stack}", E_USER_WARNING);
}

About

PHP-API for the well known Smush.it™ image optimizer.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages