xref: /dokuwiki/vendor/splitbrain/slika/src/Slika.php (revision 5c25a0714a8ef36fe8b57b70c8b59ee09eccaac1)
192a8473aSAndreas Gohr<?php
292a8473aSAndreas Gohr
392a8473aSAndreas Gohr
492a8473aSAndreas Gohrnamespace splitbrain\slika;
592a8473aSAndreas Gohr
6*5c25a071SAndreas Gohr/**
7*5c25a071SAndreas Gohr * Factory to process an image using an available Adapter
8*5c25a071SAndreas Gohr */
992a8473aSAndreas Gohrclass Slika
1092a8473aSAndreas Gohr{
11*5c25a071SAndreas Gohr    /** rotate an image counter clock wise */
1292a8473aSAndreas Gohr    const ROTATE_CCW = 8;
13*5c25a071SAndreas Gohr    /** rotate an image clock wise */
1492a8473aSAndreas Gohr    const ROTATE_CW = 6;
15*5c25a071SAndreas Gohr    /** rotate on it's head */
1692a8473aSAndreas Gohr    const ROTATE_TOPDOWN = 3;
1792a8473aSAndreas Gohr
18*5c25a071SAndreas Gohr    /** these can be overwritten using the options array in run() */
1992a8473aSAndreas Gohr    const DEFAULT_OPTIONS = [
2092a8473aSAndreas Gohr        'quality' => 92,
2192a8473aSAndreas Gohr        'imconvert' => '/usr/bin/convert',
2292a8473aSAndreas Gohr    ];
2392a8473aSAndreas Gohr
2492a8473aSAndreas Gohr    /**
2592a8473aSAndreas Gohr     * This is a factory only, thus the constructor is private
2692a8473aSAndreas Gohr     */
2792a8473aSAndreas Gohr    private function __construct()
2892a8473aSAndreas Gohr    {
2992a8473aSAndreas Gohr        // there is no constructor.
3092a8473aSAndreas Gohr    }
3192a8473aSAndreas Gohr
3292a8473aSAndreas Gohr    /**
3392a8473aSAndreas Gohr     * Start processing the image
3492a8473aSAndreas Gohr     *
3592a8473aSAndreas Gohr     * @param string $imagePath
3692a8473aSAndreas Gohr     * @param array $options
3792a8473aSAndreas Gohr     * @return Adapter
3892a8473aSAndreas Gohr     * @throws Exception
3992a8473aSAndreas Gohr     */
4092a8473aSAndreas Gohr    public static function run($imagePath, $options = [])
4192a8473aSAndreas Gohr    {
4292a8473aSAndreas Gohr        $options = array_merge(self::DEFAULT_OPTIONS, $options);
4392a8473aSAndreas Gohr
4492a8473aSAndreas Gohr        if (is_executable($options['imconvert'])) {
4592a8473aSAndreas Gohr            return new ImageMagickAdapter($imagePath, $options);
4692a8473aSAndreas Gohr        }
4792a8473aSAndreas Gohr
4892a8473aSAndreas Gohr        if (function_exists('gd_info')) {
4992a8473aSAndreas Gohr            return new GdAdapter($imagePath, $options);
5092a8473aSAndreas Gohr        }
5192a8473aSAndreas Gohr
5292a8473aSAndreas Gohr        throw new Exception('No suitable Adapter found');
5392a8473aSAndreas Gohr    }
5492a8473aSAndreas Gohr
5592a8473aSAndreas Gohr}
56