PHP code example of selective / image-type

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

    

selective / image-type example snippets


use Selective\ImageType\ImageTypeDetector;
use Selective\ImageType\Provider\RasterProvider;
use Selective\ImageType\Provider\HdrProvider;
use Selective\ImageType\Provider\RawProvider;
use Selective\ImageType\Provider\VectorProvider;
use SplFileObject;

$file = new SplFileObject('example.jpg');

$detector = new ImageTypeDetector();

// Add image detectors
$detector->addProvider(new HdrProvider());
$detector->addProvider(new RawProvider());
$detector->addProvider(new VectorProvider());
$detector->addProvider(new RasterProvider());

$imageType = $detector->getImageTypeFromFile($file);

// Get the image format
echo $imageType->getFormat(); // jpeg

// Get the mime type
echo $imageType->getMimeType(); // image/jpeg

$image = new SplTempFileObject();

$image->fwrite('my file content');

$detector = new ImageTypeDetector();

// Add image detectors
$detector->addProvider(new RasterProvider());

echo $detector->getImageTypeFromFile($file)->getFormat();