Skip to content

Php library for converting and caching images to Webp .webp, JpegXr .jxr, Jpeg 2000 .jp2

Notifications You must be signed in to change notification settings

izica/php-progressive-images-webp-jp2-jxr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

Library converts your images to progressive images formats

  • Webp
  • Jpeg 2000
  • Jpeg XR

Warning

Currently works only on Unix systems, you can help me achieve cross-platform waiting for your pull requests.

Requirements

imagemagick
webp
libjxr-tools

Installation

sudo apt-get install imagemagick webp libjxr-tools
composer require izica/php-progressive-images-webp-jp2-jxr

Usage(Examples)

<?php
$obData = \Izica\ProgressiveImages::fromFileSource('/upload/iblock/fe7/fe7728c5f2c6763693eb1d9ef105c46c.png')
    ->setFileName('custom-file-name')
    ->setDestinationFolder($_SERVER['DOCUMENT_ROOT'] . '/test/cache/')
    ->convert();
/*

Izica\ProgressiveImagesResponse Object
(
    [source] => /upload/iblock/fe7/fe7728c5f2c6763693eb1d9ef105c46c.png
    [webp] => /test/cache/custom-file-name.webp
    [jpeg2000] => /test/cache/custom-file-name.jp2
    [jpegxr] => /test/cache/custom-file-name.jxr
)
 */
?>

<picture>
    <source srcset="<?=$obData->jpegxr;?>" type='image/vnd.ms-photo'>
    <source srcset="<?=$obData->jpeg2000;?>" type='image/jp2'>
    <source srcset="<?=$obData->webp;?>" type="image/webp">
    <img src="<?=$obData->source;?>" alt="">
</picture>
$arData = \Izica\ProgressiveImages::fromFileSource('/upload/iblock/fe7/fe7728c5f2c6763693eb1d9ef105c46c.png')
    ->setFileName('custom-file-name')
    ->setDestinationFolder($_SERVER['DOCUMENT_ROOT'] . '/test/cache/')
    ->convert()
    ->toArray();
/*
    Array
    (
        [source] => /upload/iblock/fe7/fe7728c5f2c6763693eb1d9ef105c46c.png
        [webp] => /test/cache/custom-file-name.webp
        [jpeg2000] => /test/cache/custom-file-name.jp2
        [jpegxr] => /test/cache/custom-file-name.jxr
    )
 */
$arData = \Izica\ProgressiveImages::fromFileSource('/upload/iblock/fe7/fe7728c5f2c6763693eb1d9ef105c46c.png')
    ->setFileName('custom-file-name')
    ->setDestinationFolder($_SERVER['DOCUMENT_ROOT'] . '/test/cache/')
    ->withoutJpegXr()
    ->withoutJpeg2000()
    ->convert();
/*
 Izica\ProgressiveImagesResponse Object
   (
       [source] => /upload/iblock/fe7/fe7728c5f2c6763693eb1d9ef105c46c.png
       [webp] => /test/cache/custom-file-name.webp
       [jpeg2000] => 
       [jpegxr] => 
   )
 */