PHP code example of flokosiol / focus

1. Go to this page and download the library: Download flokosiol/focus 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/ */

    

flokosiol / focus example snippets



  // you need a Kirby image object like this
  $image = $page->images()->first();

  // crop a square of 200px x 200px
  echo $image->focusCrop(200);

  // crop a rectangle of 300px x 200px
  echo $image->focusCrop(300, 200);

  // crop a rectangle of 200px x 400px with a quality of 80%
  echo $image->focusCrop(200, 400, ['quality' => 80]);

  // crop a grayscale square of 300px x 300px
  echo $image->focusCrop(300, 300, ['grayscale' => true]);

  // crop a rectangle of 200px x 300px and force coordinates (overrides user input)
  echo $image->focusCrop(200, 300, ['focusX' => 0.3, 'focusY' => 0.6]);


  $url = $image->focusCrop(200, 300)->url();
  $filename = $image->focusCrop(150)->filename();


  $x = $image->focusX();
  $y = $image->focusY();

  $x = $image->focusPercentageX();
  $y = $image->focusPercentageY();

<div style="background-image: url( echo $image->url() 

return [
  'flokosiol' => [
    'focus' => [
      'presets' => [
        'square' => [
          'width'=> 500
        ],
        'rectangle' => [
          'width'=> 500,
          'height'=> 300,
          'options' => [
            'grayscale' => true
          ]
        ]
      ]
    ]
  ]
];

<img 
  src="<?= $image->focusCrop(1000, 1000)->url() 

return [
  'flokosiol' => [
    'focus' => [
      'srcsets' => [
        'homer' => [
          '800w' => [
            'width' => 800,
            'height' => 800,
          ],
          '1400w' => [
            'width' => 1400,
            'height' => 1400,
          ]
        ],
        'bart' => [
          '100w' => [
            'width' => 100,
            'height' => 100,
          ],
          '900w' => [
            'width' => 900,
            'height' => 900,
          ]
        ]
      ]
    ]
  ]
];

<?= $image->focusSrcset('bart')