Download the PHP package pelock/yii2-imgopt without Composer

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

Image widget with an auto WebP file generation for Yii2 Framework

ImgOpt is an image optimization widget for Yii2 Framework with auto WebP & AVIF image formats generation from PNG and JPG files.

https://www.yiiframework.com/extension/pelock/yii2-imgopt

How to make my website faster?

My website had all the beautiful images and screenshots, but there was one problem. Most of them were in PNG format, some of them weighted around 200 kB. And it adds up to the point where my website loading time was just slow.

I found about the WebP format, read that it's supported in the latest browsers and if it's not (only older Safari browsers), there's a way to overcome this and serve the default PNG or JPG images. Perfect.

But the entire process would require me to go manually and use some sort of image conversion tool, upload new WebP images to the server and upgrade my HTML code.

To hell with that! We can do better!

Automate PNG & JPG to WebP & AVIF conversion

I have decided to create a Yii2 widget that would automate this task.

What it does? Instead of static images like this:

it will automatically generate an extra image in new WebP format (in the same directory, where the provided image is located) and serve it to your browser in HTML <picture> tag, with a default fallback to the original image for browsers that don't support WebP images.

Replace your IMG tag within your HTML templates with a call to:

(Image path is relative to Yii2 Framework @webroot alias)

And once run, the widget code will generate a new WebP & AVIF image files on the fly (original image is left untouched) and he following HTML code gets generated:

The browser will pick up the best source for the provided image, and thanks to revolutionary WebP and AVIF compression, it will make your website loading faster.

Image lazy-loading

Lazy images loading makes the browser load the images when it reach a certain point, after which the image became visible in the current browser tab. You can use this pure HTML feature (no JS involved) from within the widget:

The generated output looks like this:

Use it to make your website loading times even faster.

AVIF image generation (new in v1.3.0)

ImgOpt will automatically generate AVIF file if it's supported by the existing PHP installation. If the conversion function is not available, it will just skip this step.

Automatic WebP generation for updated images (new in v1.2.0)

ImgOpt will set the modification date of the generated WebP image to match the modification date of the original image file.

If ImgOpt detects that a file modification date of the source image file is different than the date of the previously generated WebP image file - it will automatically re-create the new WebP image file!

Installation

The preferred way to install the library is through the composer.

Run:

Or add:

to therequire section within your composer.json config file.

The installation package is available at https://packagist.org/packages/pelock/yii2-imgopt

The Yii2 extension is available at https://www.yiiframework.com/extension/pelock/yii2-imgopt

Source code is available at https://github.com/PELock/yii2-imgopt

Image quality

I knew you would ask about it! By default the conversion tries all the steps from 100% output image quality down to 70% to generate the WebP file that is smaller than the original image.

Original PNG (181 kB) Optimized WebP (60 kB)
Social Media Bot Social Media Bot

If the generated WebP or AVIF image is larger than the original image, the default <img> tag will be generated.

Disable WebP/AVIF images serving

If for some reason you want to disable WebP file serving via the HTML <picture> tag, you can do it per widget settings:

Recreate WebP/AVIF files

The widget code automatically detects if there's a WebP/AVIF images in the directory with the original image. If it's not there - it will recreate them. It's only done once.

If you wish to force the widget code to recreate it anyway, pass the special param to the widget code:

You might want to recreate all of the WebP and AVIF files and to do that without modifying, change the widget source code from:

to:

Lightbox 2 integration

You can also generate Lightbox (https://lokeshdhakar.com/projects/lightbox2/) friendly images.

Instead of:

You can replace it with more compact widget code:

And it will generate this HTML code:

Bugs, questions, feature requests

If you are interested in my software or have any questions regarding it, technical or legal issues, or if something is not clear, please contact me. I'll be happy to answer all of your questions.

Bartosz Wójcik


All versions of yii2-imgopt with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4.0
yiisoft/yii2 Version >=2.0.4
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 pelock/yii2-imgopt contains the following files

Loading the files please wait ....