1. Go to this page and download the library: Download imageoptim/imageoptim library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
imageoptim / imageoptim example snippets
= new ImageOptim\API("🔶your api username goes here🔶");
$imageData = $api->imageFromURL('http://example.com/photo.jpg') // read this image
->resize(160, 100, 'crop') // optional: resize to a thumbnail
->dpr(2) // optional: double number of pixels for high-resolution "Retina" displays
->getBytes(); // perform these operations and return the image data as binary string
file_put_contents("images/photo_optimized.jpg", $imageData);
// This line is be found, try changing the path
// and or run `composer update` in your project's directory
ary object used to store
// settings of the optimization.
$imageParams = $api->imageFromURL('http://example.com/photo.jpg');
// You set various settings on this object (or none to get the defaults).
$imageParams->quality('low');
$imageParams->resize(1024);
// Next, to start the optimizations and get the optimized image, call:
$imageData = $imageParams->getBytes();
/*
the getBytes() call may take a while to run, so it's intended to be
called only once per image (e.g. only when a new image is uploaded
to your server). If you'd like to "lazily" optimize arbitrary images
on-the-fly when they're requested, there is a better API for that:
https://im2.io/api/get
*/
// Save the image data somewhere on the server, e.g.
file_put_contents("images/photo_optimized.jpg", $imageData);
// Note that this script only prepares a static image file
// (in this example in images/photo_optimized.jpg),
// and does not serve it to the browser. Once the optimized
// image is saved to disk you should serve it normally
// as you'd do with any regular image file.
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.