2017 © Pedro Peláez
 

library imgprocess

Coercive Utility ImgProcess

image

coercive/imgprocess

Coercive Utility ImgProcess

  • Friday, June 1, 2018
  • by Coercive
  • Repository
  • 1 Watchers
  • 1 Stars
  • 425 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 48 % Grown

The README.md

Coercive ImgProcess

  • The ImgProcess allows you to easily resize your images in PHP with util options like "cover" which allows to cover a dimensioned area provided just as would do the css property of the same name; Or the "crop" that allows you to crop a specific area of your image.

Get

composer require coercive/imgprocess

Resize image

use Coercive\Utility\ImgProcess\ImgProcess;

# INIT
$img = new ImgProcess;

# QUALITY (optional : default jpg 60 /  png 0)
$img
    ->setJpgQuality(50)
    ->setPngCompression(5);

# EXAMPLE SET
$img
    ->setOverwriting(true)
    ->setInputPath('source/path/image_name.jpg')
    ->setOutputPath('output/path/new_image.jpg')
    ->setSourceCoordinate('RIGHT', 'BOTTOM')
    ->setOutputSize(1000, 1000);

# PROCESS
$bVerif = $img->sameSize();
// or
$bVerif = $img->myOwnSize(500);
// or
$bVerif = $img->crop();
// or
$bVerif = $img->cover();
// ...

# HANDLE ERRORS
if( !$bVerif ) {
    if( $aError = $img->getError() ) {
        foreach ($aError as $sMessage) { echo "

$sMessage, (*1)

"; } die('Shutdow After Process'); } else { die('Shutdow After Process : Unknow Error.'); } }

Detect image quality

# DETECT IMAGE QUALITY (base on linux 'identify')
$iQuality = ImgProcess::getImageQuality('/path/image_name.jpg');

Get image size

$sizes = ImgProcess::getImageSize('/path/image_name.jpg');
echo $sizes['width'] . ' x ' . $sizes['height']

---

Html responsive image

Example of html content to reformat., (*2)

<section>
    <p>Hello World</p>
    <img src="my-image.jpg" alt="Hello World" />
</section>

Instantiate basic options

use Coercive\Utility\ImgProcess\ImgResponsive;

$rii = (new ImgResponsive)
    ->overwrite(true)
    ->data($data)
    ->path('/rootpath/server/img', '/realpath/img')

Mode SRCSET with multiplier option

$rii
    ->modeSrcset(true)
    ->size(500, '1x', true)
    ->size(1000, '2x')
    ->size(1500, '3x')

Mode SRCSET with query option

$rii
    ->modeSrcset()
    ->size(645, '(max-width: 750px) 645px')
    ->size(1095, '(min-width: 751px) and (max-width: 938px) 1095px')
    ->size(862, '(min-width: 939px) and (max-width: 1169px) 832px')
    ->size(1095, '(min-width: 1170px) 1095px', true)

Mode PICTURE with query option

$rii
    ->modePicture()
    ->size(645, '(max-width: 750px) 645px')
    ->size(1095, '(min-width: 751px) and (max-width: 938px) 1095px')
    ->size(862, '(min-width: 939px) and (max-width: 1169px) 832px')
    ->size(1095, '(min-width: 1170px) 1095px', true)

Resolve image src path

Here is an example of retrieving the good image path if you have some complex directory tree., (*3)

$rii->resolve(function ($path) {
    $path = urldecode($path);

    if(!preg_match('`/(?P<env>testmode|production)/filedirectory/(?P<relpath>/.+)$`', $path, $matches)) {
        return '';
    }

    $env = $matches['env'];
    $relpath = $matches['relpath'];
    return  preg_replace('`testmode|production`', $env, '/root/production/specific/path') . $relpath;
});

Start process and get HTML

try {
    $rii->process();
}
catch (Exception $e) {
    // do something
    echo $e->getMessage();
    exit;
}

$formattedHtml = $rii->getHtml();
if(!$formattedHtml) {
    die('KO');
}

echo $formattedHtml;

The Versions

01/06 2018

dev-master

9999999-dev http://coercive.fr

Coercive Utility ImgProcess

  Sources   Download

MIT GNU

The Requires

  • php >=7

 

01/06 2018

0.0.9

0.0.9.0 http://coercive.fr

Coercive Utility ImgProcess

  Sources   Download

MIT

The Requires

  • php >=7

 

23/04 2018

0.0.8

0.0.8.0 http://coercive.fr

Coercive Utility ImgProcess

  Sources   Download

MIT

The Requires

  • php >=7

 

07/02 2018

0.0.7

0.0.7.0 http://coercive.fr

Coercive Utility ImgProcess

  Sources   Download

MIT

The Requires

  • php >=7

 

07/02 2018

0.0.6

0.0.6.0 http://coercive.fr

Coercive Utility ImgProcess

  Sources   Download

The Requires

  • php >=7

 

06/02 2018

0.0.5

0.0.5.0 http://coercive.fr

Coercive Utility ImgProcess

  Sources   Download

GNU

The Requires

  • php >=7

 

07/06 2017

0.0.3

0.0.3.0 http://coercive.fr

Coercive Utility ImgProcess

  Sources   Download

GNU

The Requires

  • php >=7

 

07/06 2017

0.0.4

0.0.4.0 http://coercive.fr

Coercive Utility ImgProcess

  Sources   Download

GNU

The Requires

  • php >=7

 

04/06 2017

0.0.2

0.0.2.0 http://coercive.fr

Coercive Utility ImageEngine

  Sources   Download

GNU

The Requires

  • php >=7

 

04/06 2017

0.0.1

0.0.1.0 http://coercive.fr

Coercive Utility ImageEngine

  Sources   Download

GNU

The Requires

  • php >=7